/*
Example: read file into string in C language
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main() {
char filename[] = "test.txt";
char * buffer = 0;
long length;
FILE * f = fopen (filename, "rb");
if (f)
{
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc (length);
if (buffer)
{
fread (buffer, 1, length, f);
}
fclose (f);
}
if (buffer)
{
// process data
printf("%s",buffer);
}
return 0;
}Sourcetual.www:turi.com