c read file content

Solutions on MaxInterview for c read file content by the best coders in the world

showing results for - "c read file content"
Angelo
16 Sep 2016
1char * buffer = 0;
2long length;
3FILE * f = fopen (filename, "rb");
4
5if (f)
6{
7  fseek (f, 0, SEEK_END);
8  length = ftell (f);
9  fseek (f, 0, SEEK_SET);
10  buffer = malloc (length);
11  if (buffer)
12  {
13    fread (buffer, 1, length, f);
14  }
15  fclose (f);
16}
17
18if (buffer)
19{
20  // start to process your data / extract strings here...
21}
22