V
vasudevmukherjee
Hi! Can somebody help tell me why the following code gives a garbage
value while producing first student's name, whereas it gives the names
correctly for other three students - I really fail to understand since
it is not generating the required results.- Thank you in anticipation -
Vasudev.
#include <stdio.h>
main ()
{
char student[4][30], *x[4][30];
int i, j,k;
printf("Student's name!\n");
for(i=0;i<=3;i++)
{
gets(student);
x[30]=&student[30];
}
printf("\nYou have typed the following names.\n");
for(i=0;i<=3;i++)
{
puts(*x);
}
printf("\nHow many names do you want to republish (choice 1 to
4)??\n");
scanf("%d",&k);
k=k-1;
if(k>=0)
{
for(j=0;j<=k;j++)
{
printf("Which Student's name do you want to know, 1st, 2nd, 3rd or
4th??\n");
scanf("%d", &i);
i=i-1;
printf("Student's name = %s\n", *x);
}
}
}
value while producing first student's name, whereas it gives the names
correctly for other three students - I really fail to understand since
it is not generating the required results.- Thank you in anticipation -
Vasudev.
#include <stdio.h>
main ()
{
char student[4][30], *x[4][30];
int i, j,k;
printf("Student's name!\n");
for(i=0;i<=3;i++)
{
gets(student);
x[30]=&student[30];
}
printf("\nYou have typed the following names.\n");
for(i=0;i<=3;i++)
{
puts(*x);
}
printf("\nHow many names do you want to republish (choice 1 to
4)??\n");
scanf("%d",&k);
k=k-1;
if(k>=0)
{
for(j=0;j<=k;j++)
{
printf("Which Student's name do you want to know, 1st, 2nd, 3rd or
4th??\n");
scanf("%d", &i);
i=i-1;
printf("Student's name = %s\n", *x);
}
}
}