FILE *file;
file=fopen("Data/gamecfg.txt","rt");
fputs("This is a test",file);
fclose(file);
any ideas? I can read the data fine with fgets, but the function above won''t write data to the file.
Thanks,
Joe
JoeMont001@aol.com
writing data to a file
ok, I have an empty text file. I open the file, try to write some stuff to it, and close it. Like this:
There are some mistakes in this line:
file=fopen("Data/gamecfg.txt","rt");
it should be:
file=fopen("Data\\gamecfg.txt","r+");
Edited by - +AA_970+ on June 26, 2000 2:53:18 PM
file=fopen("Data/gamecfg.txt","rt");
it should be:
file=fopen("Data\\gamecfg.txt","r+");
Edited by - +AA_970+ on June 26, 2000 2:53:18 PM
It''s because you are opening the file for read access only.
Mark Fassett
Laughing Dragon Entertainment
http://www.laughing-dragon.com
Mark Fassett
Laughing Dragon Entertainment
http://www.laughing-dragon.com
Doesn''t "rt" mean "read only text"? You want to have "r+t" so you can read and write at the same time.
Andrew
Andrew
quote:Original post by +AA_970+
There are some mistakes in this line:
file=fopen("Data/gamecfg.txt","rt");
it should be:
file=fopen("Data\\gamecfg.txt","r+");
Edited by - +AA_970+ on June 26, 2000 2:53:18 PM
That''s not true, / works too, and for maximum portability you should always use / instead of \ when writing paths. DOS and Windows support both / and \ as directory and drive separators, but Linux and Unix only support /. So using / will save you some time if you port your game to Linux/Unix
- Muzzafarath
Mad House Software
The Field Marshals
Ok i just checked the VC++ help file, i didn''t realize "t" was actually an access mode. So acraig is correct, it would be "r+t"
BTW, thanks for the tip Muzzafarath, i never knew that you could use the foward slash in filenames
+AA_970+
BTW, thanks for the tip Muzzafarath, i never knew that you could use the foward slash in filenames
+AA_970+
well I guess that's why I could read the data. I got it to work. here's the final code:
Thanks guys,
Joe
JoeMont001@aol.com
Edited by - Julio on June 26, 2000 8:50:38 PM
FILE *file; file=fopen("Data/gamecfg.txt","r+t"); fprintf(file,"This is a test"); fclose(file);
Thanks guys,
Joe
JoeMont001@aol.com
Edited by - Julio on June 26, 2000 8:50:38 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement