C examples for File:Text File
Read Integers Stored in a Text File using the function fscanf()
#include <stdio.h> int main(){/*from w ww . ja v a2 s. c om*/ int m = 0, n, k = 0; FILE *fptr; fptr = fopen("C:\\Code\\numbers.dat", "r"); if (fptr != NULL) { puts("File numbers.dat is opened successfully."); m = fscanf(fptr, "%d", &n); while(m != EOF){ printf("%d ", n); m = fscanf(fptr, "%d", &n); } printf("\n"); k = fclose(fptr); if(k == -1) puts("File-closing failed"); if(k == 0) puts("File is closed successfully."); } else puts("File-opening failed"); return(0); }