How to store the contents of a file into a variable



Hi.

I want to store the contents of a file into a variable:
------------
char file_name[] = "/home/user/foo.txt";
FILE *my_file;
my_file = fopen(file_name, "r");

char *file_data;
fscanf(my_file, file_data);

printf("%s\n", file_name);
printf("%s\n", file_data);
-------------------------

But I get:
------------------------
/home/user/foo.txt
(null)
-------------------------

Of course, my 'foo.txt' file is not empty. Whay am I doing wrong? Thx.

.



Relevant Pages