Read string from a file : File Read « File « C Tutorial






#include<stdio.h>

void main(){

    FILE *fp;

    fp = fopen("test","a");
    fprintf(fp,"%d %s %d\n",1,"1 a 1",2);
    fclose(fp) ;

    fp = fopen("test","r");

    char rollno[10],name[10],marks[10];
    fscanf(fp,"%d %s %d\n",&rollno,&name,&marks);
    printf(" %d         %s    %d\n",rollno,name,marks);


    fclose(fp);
}








13.2.File Read
13.2.1.Read string from a file