The following code create a file file.text and prints the following in the file "
1 2
3 4
What is the most efficient way to print the value 4 on the console. In actual case I have a 2000 x 2000 matrix, and I have to access let say the value [2000][1500] and print the same on console. by efficient I mean how quickly the pointer can go there, fetch the data, and send it to the display buffer.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * fp;
fp = fopen ("file.txt", "w+");
fprintf(fp, "%s %s %s %d", "1", "2", "\n" "3", 4);
fclose(fp);
return(0);
}
"\n"
)) byy
: the number of the line you wish to get (in this case i think2000
?) and then add (2 (same) timesx
). If your numbers are not always 1 digit long, you need to read the file by chunks, count the"\n"
's and then count the spaces. – Eregrith