User Define Function

Non-platform specific questions.

User Define Function

Postby magneto » Sat Jul 17, 2010 5:24 pm

Hi,
I am new to Game Editor, I have developed a multi-level game and I have written several functions inside Global Editor.
Everthing looks fine. Recently I added a function to write the User defined variable into a file.
When I look at the function list in global editor I can see all of my functions that I have written.
Then I added the following function to read the file. I get warning for each fgets function ( Conversion from Char array to *Char) and I confirm the action. Then when I look at function list in Global Editor I can not find any of my functions. All of my functions disappear from the list.

void ReadData()
{
FILE *f2;
char bline[20];

if ( f2 != NULL )
{
f2 = fopen("data.sr","r");
fgets(&bline,20,f2);
fgets(&bline,20,f2);
Totals =atof(bline);
fgets(&bline,20,f2);
fgets(&bline,20,f2);
plife= atoi(bline);
fclose(f2);
}
}

I know the problem sits between the keyboard and the chair so I do appreciate your help.
magneto
 
Posts: 6
Joined: Sat Jul 17, 2010 5:05 pm
Score: 0 Give a positive score

Re: User Define Function

Postby magneto » Sat Jul 17, 2010 6:05 pm

Correction to the funtion

void ReadData()
{
FILE *f2;
char bline[21];
f2=fopen("data.sr","r");

if ( f2 != NULL )
{

fgets(&bline,20,f2);
fgets(&bline,20,f2);
Totals =atof(bline);
fgets(&bline,20,f2);
fgets(&bline,20,f2);
plife= atoi(bline);
fclose(f2);
}
}
magneto
 
Posts: 6
Joined: Sat Jul 17, 2010 5:05 pm
Score: 0 Give a positive score

Re: User Define Function

Postby magneto » Sat Jul 17, 2010 8:12 pm

The correction made to the function. If you notice I had open statement inside the if statement.

None the less the problem still exists.
magneto
 
Posts: 6
Joined: Sat Jul 17, 2010 5:05 pm
Score: 0 Give a positive score

Re: User Define Function

Postby makslane » Sat Jul 17, 2010 11:53 pm

Try this:

Code: Select all
void ReadData()
{
   FILE *f2;
   char bline[21];
   f2=fopen("data.sr","r");

   if ( f2 != NULL )
   {

      fgets(bline,20,f2);
      fgets(bline,20,f2);
      Totals =atof(bline); //You will get an error here
      fgets(bline,20,f2);
      fgets(bline,20,f2);
      plife= atoi(bline); //You will get an error here. I think you want to get the contents of the string. So,  try something like atoi(bline[0]);
      fclose(f2);
   }
}
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: User Define Function

Postby magneto » Sun Jul 18, 2010 4:19 am

Thanks Makslane.
I found the solution to the problem.
My original code worked as soon as I changed the array declaration

from

char bline[21];

to

char bline[21]="";

No warning and no error. And everything works fine. :D
magneto
 
Posts: 6
Joined: Sat Jul 17, 2010 5:05 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron