krishna_1980
Junior Member level 3
the following code is giving runtime error as "segmentation fault".why?
char *str;
fp=fopen("f1.txt","r");
fgets(str,10,fp);
puts(str);
but the following code is working.................................................
char *str;
fp=fopen("f1.txt","r");
fgets(str,10,fp);
for(i=0;i<10;i++)
printf("%c",*(str+i));
char *str;
fp=fopen("f1.txt","r");
fgets(str,10,fp);
puts(str);
but the following code is working.................................................
char *str;
fp=fopen("f1.txt","r");
fgets(str,10,fp);
for(i=0;i<10;i++)
printf("%c",*(str+i));