- Joined
- Sep 6, 2007
- Messages
- 5
- Reaction score
- 0
If you could find any problem with the below code lines to understand structures in C, please post back the remedies
#include<stdio.h>
#include<conio.h>
int main()
{
int j;
struct IP{
int Ver;
int PNo;
char Data[50];
};
struct IP i[2],*k,*m;
for(j=0;j<2;j++)
{
printf("Enter the Version Number : ");
scanf("%d",&i[j].Ver);
printf("Enter the Packet Number : ");
scanf("%d",&i[j].PNo);
printf("Sizeof(Version)%d",sizeof(i[j].Ver));
printf("\nVersion Number : %d\n\n",i[j].Ver);
}
printf("Fill the payload for Packet %d (Max 50 Characters) : ",i[0].PNo);
gets(i[0].Data);
k=&i[1];
printf("\nFill the payload for Packet %d (Max 50 Characters) : ",k->PNo);
gets(k->Data);
printf("First Version Number : %d\n",i[0].Ver);
printf("Payload : %s\n",i[0].Data);
printf("Second Version Number : %d\n",k->Ver);
printf("Payload : %s\n",k->Data);
getch();
return 0;
}
the problem i found is with the highlighted lines where the execution is not good and for more details the execution is good without the block of for loop
#include<stdio.h>
#include<conio.h>
int main()
{
int j;
struct IP{
int Ver;
int PNo;
char Data[50];
};
struct IP i[2],*k,*m;
for(j=0;j<2;j++)
{
printf("Enter the Version Number : ");
scanf("%d",&i[j].Ver);
printf("Enter the Packet Number : ");
scanf("%d",&i[j].PNo);
printf("Sizeof(Version)%d",sizeof(i[j].Ver));
printf("\nVersion Number : %d\n\n",i[j].Ver);
}
printf("Fill the payload for Packet %d (Max 50 Characters) : ",i[0].PNo);
gets(i[0].Data);
k=&i[1];
printf("\nFill the payload for Packet %d (Max 50 Characters) : ",k->PNo);
gets(k->Data);
printf("First Version Number : %d\n",i[0].Ver);
printf("Payload : %s\n",i[0].Data);
printf("Second Version Number : %d\n",k->Ver);
printf("Payload : %s\n",k->Data);
getch();
return 0;
}
the problem i found is with the highlighted lines where the execution is not good and for more details the execution is good without the block of for loop