Page 1 of 1

Script for reading text from a file??

PostPosted: Mon May 10, 2004 4:39 am
by Just4Fun
What is the Script for reading text from a file :?:

Thank You...

PostPosted: Mon May 10, 2004 2:10 pm
by makslane
Use this:


Code: Select all
char textArray[10][256]; //Max 10 text of 255 characters
int nText = 0; //Number of texts read


void readText(char * fileName)
{
 char line[256];
 FILE *arq = fopen(fileName, "r");

 if(arq)
 {
  while(fgets(line, 255, arq) && nText < 10)
  {
    if(strlen(line) > 0) //Dont put empty lines
    {
      strcpy(textArray[nText], line);
      nText++;
    }
  }
 }
}



See the complete demo at:

http://game-editor.com/examples/randomtext.zip

PostPosted: Mon May 10, 2004 4:17 pm
by Just4Fun
I love you Makslane! :lol:

Thank you.. Thank you...Thank you...

PostPosted: Fri May 28, 2004 1:52 pm
by ingsan
What is the meaning of strlen ?
And what must I understand by FILE *arq = fopen(fileName, "r"); especially the "r". Where does it come from ? To what does it refer ?

Ohhh Questions Questions Questions ... :?

PostPosted: Fri May 28, 2004 3:26 pm
by makslane
- strle return the text lenght
- the "r" is the read option