Splint
asked on
getting data from a txt file
I have a very basic game that I am working on and want to use a read only text file to save basic dat (character name, stats etc) I can make the file as I want but cannot figure out how to get said data back out.
-Splint
-Splint
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, or use the old C stuff:
#include <stdio.h>
main()
{
FILE *inputfile;
int i = 200;
char read[200];
char filename[] = "c:\\myfile.txt";
if ( (inputfile = fopen(filename, "r") ) != NULL)
{
while (fgets(read,i,inputfile))
{
cout >> read; //This while statement is for printing every line of the file.
}
}
}
#include <stdio.h>
main()
{
FILE *inputfile;
int i = 200;
char read[200];
char filename[] = "c:\\myfile.txt";
if ( (inputfile = fopen(filename, "r") ) != NULL)
{
while (fgets(read,i,inputfile))
{
cout >> read; //This while statement is for printing every line of the file.
}
}
}
>> Yes, or use the old C stuff:
This is the C++ topic area not the C topic area. :-)
This is the C++ topic area not the C topic area. :-)
ASKER
Alright Thanks a lot, I'll look into it
ps: I say read only because I make the file and then delete it when new data is added. read only will prevend at least the most passive of tampering
ps: I say read only because I make the file and then delete it when new data is added. read only will prevend at least the most passive of tampering
#include <stdio.h>
main()
{
FILE *inputfile;
int i = 200;
char read[200];
char filename[] = "c:\\myfile.txt";
if ( (inputfile = fopen(filename, "r") ) != NULL)
{
while (fgets(read,i,inputfile))
{
cout >> read; //This while statement is for printing every line of the file.
}
}
}