Read string from a file


Levels of difficulty: / perform operation:

Program to Read string from a file using fprintf function in c


Program

#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);
}





Quantitative Aptitude
Reasoning
Programming
Interview