How to store the contents of a file into a variable
- From: francescomoi@xxxxxxxxxx
- Date: 28 Apr 2005 10:47:36 -0700
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.
.
- Follow-Ups:
- Re: How to store the contents of a file into a variable
- From: Thomas Matthews
- Re: How to store the contents of a file into a variable
- From: Eric Sosman
- Re: How to store the contents of a file into a variable
- Prev by Date: Re: Median
- Next by Date: Re: When using select call on many sockets, how to check if one of them is closed
- Previous by thread: Converting large strings to numbers
- Next by thread: Re: How to store the contents of a file into a variable
- Index(es):
Relevant Pages
|