Function for reading lines in a txtfile
Hello!
Im developing a mapeditor in c/c++ and I havnt got a good funktion for reading lines from a file. I was going to make a file that has a value or a string on each line and I would like to read that number or string one by one.
This to make it as easy as possible.
Marcus
FILE * File
File = fopen("filename.txt", "r");
then use fscanf (check MSDN for all the options) to read formatted data from the file.
Good luck!
Jasper
File = fopen("filename.txt", "r");
then use fscanf (check MSDN for all the options) to read formatted data from the file.
Good luck!
Jasper
int yHeight[132];
FILE* stream;
stream = fopen( "yValue.txt", "r" );
if( stream == NULL )
Error_Msg("The file yValue.txt was not opened\n" );
else
{
/* Set pointer to beginning of file: */
fseek( stream, 0L, SEEK_SET );
/* Read data back from file: */
for(int i = 0; i < 132; i++)
fscanf( stream, "%i", &yHeight );
fclose( stream );
}
//reads back 132 integers from a file, a new integer starts after a space so: 33 2 5 3 , would be four numbers
FILE* stream;
stream = fopen( "yValue.txt", "r" );
if( stream == NULL )
Error_Msg("The file yValue.txt was not opened\n" );
else
{
/* Set pointer to beginning of file: */
fseek( stream, 0L, SEEK_SET );
/* Read data back from file: */
for(int i = 0; i < 132; i++)
fscanf( stream, "%i", &yHeight );
fclose( stream );
}
//reads back 132 integers from a file, a new integer starts after a space so: 33 2 5 3 , would be four numbers
We are here just like this,It really doesn't matter why.The world is here like it is,'We could laugh we could cry.Is it good or is it bad,Wright or maybe wrong?There's no use of being sad,Without a purpose within a song.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement