Script for reading text from a file??

Non-platform specific questions.

Script for reading text from a file??

Postby Just4Fun » Mon May 10, 2004 4:39 am

What is the Script for reading text from a file :?:

Thank You...
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby makslane » Mon May 10, 2004 2:10 pm

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Just4Fun » Mon May 10, 2004 4:17 pm

I love you Makslane! :lol:

Thank you.. Thank you...Thank you...
I've learned that I still have a lot to learn.

** Makslane == Genious **
Just4Fun
 
Posts: 524
Joined: Tue Jul 01, 2003 5:19 am
Location: USA: Washington State; West Coast
Score: 6 Give a positive score

Postby ingsan » Fri May 28, 2004 1:52 pm

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 ... :?
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Fri May 28, 2004 3:26 pm

- strle return the text lenght
- the "r" is the read option
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest