Note that there are some explanatory texts on larger screens.

plurals
  1. POCSV file reading issue: with large amont of data
    text
    copied!<pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; char* getfield(char* line, int num) { char* tok = line; char* result; if (line) { do { if (!--num) { tok = strchr(line, ','); if (tok == NULL) { tok = &amp;line[strlen(line)]; } size_t fieldlen = tok - line; if (fieldlen) { result = (char*)malloc(fieldlen+1); result[fieldlen] = '\0'; strncpy(result, line, fieldlen); return result; } else { break; } } tok = strchr(line, ','); line = tok + 1; } while (tok); } result = (char*)malloc(2); strcpy(result, "0"); return result; } int main() { FILE* stream = fopen("data.csv", "r"); char line[1024]; char *pstr;int num1,num2,num3; char* value1,value2,value3; while (fgets(line, 1024, stream)) { char* tmp = strdup(line); value1=getfield(tmp, 1); value2=getfield(tmp, 2); value3=getfield(tmp, 3); num1 =strtol(value1,&amp;pstr,10); num2 =strtol(value2,&amp;pstr,10); num3 =strtol(value3,&amp;pstr,10) free(value1); free(value2); free(value3); printf("Fields 1,2,3 would be 1=%d 2=%d 3=%d\n", num1,num2,num3); // NOTE strtok clobbers tmp free(tmp); } } </code></pre> <p>above is my C code to read the file....</p> <pre><code> :::: data.csv :::: 10,34,30 10,33, 23,45,23 25,,45 </code></pre> <p>above is my file..</p> <p>here my issue is I can call the function with "num" field. so that for reading of every line I suppose to call the function 3 times.. !! so the performance is too low for the large data files.. can someone help me that I can call the function at once and It will return an array.. than I can easily store and print (e.g. for the first line array[0]=10,array[1]=34,array[2]=30 )</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload