C Tutorial/File/File Read

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Read string from a file

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