Page 1 of 1

User Define Function

PostPosted: Sat Jul 17, 2010 5:24 pm
by magneto
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.

Re: User Define Function

PostPosted: Sat Jul 17, 2010 6:05 pm
by magneto
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);
}
}

Re: User Define Function

PostPosted: Sat Jul 17, 2010 8:12 pm
by magneto
The correction made to the function. If you notice I had open statement inside the if statement.

None the less the problem still exists.

Re: User Define Function

PostPosted: Sat Jul 17, 2010 11:53 pm
by makslane
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);
   }
}

Re: User Define Function

PostPosted: Sun Jul 18, 2010 4:19 am
by magneto
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