read a file .txt in a C program -


i programing parallel openmp in c language , using code read 1 million of data .txt file.

 file *data = null;  data = fopen("1millon.txt","r");  float id, n, cord[1000000],cordy[1000000]; int ale = 1000000;   for(i=0;i<ale;i++){  fscanf (data, "%f %f", &id, &n);     cordx[i]=id;     cordy[i]=n; }  

actually "fscanf" doing when run program in normal computer. if run in cluster parallelization show me next warning ( warning: ignoring return value of ‘fscanf’, declared attribute warn_unused_result [-wunused-result] fscanf (data, "%f %f", &id, &n); ) , won't run."

do know way how read .txt file instead of "fscanf", "fread"?

thanks

fscanf()returns something. supposed detect problems , special situations. cluster configured complain that. own pc not configured that, hence not warn.

in order avoid warning on cluster, not ignore return value. i.e. check whether matched.

alternatively (void) fsanf... tells compiler "i intentionally ignore helpful return value.".

according opengroup fscanf manpages (within return value section), should expect call fscanf return 2 when it's successful @ reading 2 float values:

upon successful completion, these functions return number of matched , assigned input items; number can 0 in event of matching failure.

if returns less two, work required discard erroneous input (see below nice example of this), exit process or otherwise handle error in other manner. otherwise, future calls fscanf fail due same garbage left unread stdin.

if (fscanf(data, "%f %f", &id, &n) != 2) {     fscanf(data, "%*[^\n]"); // read , discard next newline character     fgetc(data);             // ... , discard newline character,     /* xxx: cordx[i] , cordy[i]? */ } 

Comments