Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading file into variable

Status
Not open for further replies.

iwuvc

Technical User
Jan 11, 2006
10
US
Well I want to be able to read a text file into a variable. I have made something that writes a text file. Pretty much here's a not so good example, and yeah.. I dont feal like writing correct syntax but you get the idea.
ex.
dud = fopen("hi.txt");
//unsure how to do this properly.
if (dud == 1) {
printf("woot\n");
}
else {
printf("failure\n");
}
 
Determine the file size, perhaps by using [tt]stat[/tt] or [tt]fstat[/tt]. Or maybe by opening the file in binary mode, [tt]fseek[/tt]ing to the end and [tt]ftell[/tt]ing the location.

Then [tt]malloc[/tt] that many [tt]char[/tt]s, open the file in text mode, and [tt]fread[/tt] the whole file.

I dont feal like writing correct syntax but you get the idea.
 
I'm really feeling the love :) Ok well thanks I can try hopefully look up those functions and make it. (you got tired of leechers beggin for code?)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top