Read text files

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
L_Draven
Posts: 21
Joined: Sun Mar 07, 2004 11:36 am

Read text files

Post by L_Draven »

Hi all.

I have a text file (.txt) with some text lines.

I want read line by line this file. How can i do it??

How can i do it for give me the line in a char variable???

I test with incluing fstream.h file for use file.getline() or other funcitons but dont work me.

Any idea???

I supose that i must use Read() function. I trying it but without results :-(.

Thanks.
enforceman
Posts: 26
Joined: Sat Jan 03, 2004 3:43 pm

Post by enforceman »

Here is an example in pure C; I hope everything's allright; maybe there are some typing errors
<code>

FILE *in;
char line[1024];

if(!(in=fopen("file.txt","r")))
{
printf("file not found\n");
// need to stop here !!!
}

float blah;
int bloh;
char bluh;

while(!(fgets(line,1024,in)))
{
sscanf(line,"%f %d %c", &blah, &bloh, &bluh);
printf("%f %d %c\n", blah, bloh, bluh);
}

fclose(in);

</code>

<file.txt>

0.1 500 a
-0.12 100 b
0.21 20 c
12.01 -50 d

</file.txt>


regards Tom
L_Draven
Posts: 21
Joined: Sun Mar 07, 2004 11:36 am

Post by L_Draven »

thanks enforceman

I will test it.
Post Reply