Question: CAN SOMEONE FIX THE ERROR? THIS IS MY CODE: (THE STRUCT IS ON POKEMON.H ALSO PLEASE FIX IT SO IT WORKS ON ISO C90, I'M

CAN SOMEONE FIX THE ERROR?

CAN SOMEONE FIX THE ERROR? THIS IS MY CODE: (THE STRUCT IS

THIS IS MY CODE: (THE STRUCT IS ON POKEMON.H ALSO PLEASE FIX IT SO IT WORKS ON ISO C90, I'M NOT ALLOWED TO CONVERT TO C99)

pokemon.h (struct file)

struct pokemon { int level; char name[25]; };

iofunctions.h

int readfile( struct pokemon pokearray[ ], int* num, char filename[ ] ); int writefile( struct pokemon pokearray[ ], int num, char filename[ ] );

iofunctions.c

#include

#include "iofunctions.h"

#include "pokemon.h"

int max_size;

int readfile(struct pokemon pokearray[],int *num,char filename[])

{ FILE *fptr; /*file pointer*/ /*initialize the file pointer.. if it returns NULL then error must be there in reading file */ if ((fptr = fopen(filename, "r")) == NULL) { return 0; /*unsuccessful reading of file */ /* function returns 0 if pointer returns NULL. */ } int count =0;/* denotes number of pokemons */ int data; /* number attached to each pokemon */ char name[50]; /* name of pokemon */

/* check if count is less than max size ..check whether file has reached end of line or not */ /* if not EOF then data get the data stored with pokemon */ while(count { count++; /* increase the count of pokemon */ fscanf(fptr,"%s",name); /* read the name from file */ pokearray[count-1].data=data; /* store the data in array */ strcpy(pokearray[count-1].name,name);/* store the name in array */ } *num=count;/* store the count in num */ return 1;/* means reading the file is successful */

} int writefile(struct pokemon pokearray[],int num,char filename[]) { FILE *fptr; /* delcare the file pointer */ /* initialize the file pointer.. if it returns NULL then error must be there in writing file */

if ((fptr = fopen(filename, "w")) == NULL) { return 0; /* function returns 0 if file pointer returns NULL. */ } for(int i=0;i { fprintf(fptr,"%d ",pokearray[i].data); /* write data to file */ fprintf(fptr,"%s ",pokearray[i].name);/* write name to file */ } return 1;/* means writing the file is successful */

}

int main() { printf("Enter the max size of array "); scanf("%d",&max_size);/* take input of max size of array */ struct pokemon *pokearray =(struct pokemon*)malloc(sizeof(struct pokemon)*max_size);/* allocate space */ int num=0;/* intialize num variable */ printf("Enter the file to be read "); char filename[50]; scanf("%s",filename);/* input the file name to be read */

if(readfile(pokearray,&num,filename)==0) /* call the readfile function */ { printf("Error in reading the file "); /* error */ } else { printf("File read successfully %d pokemons has been stored in the array ",num); printf("Enter the name of the file on which data is to be written "); scanf("%s",filename);/* input the file name of output file */ if(writefile(pokearray,num,filename)==0) { printf("Error in writing the file ");/* error */ } else { printf("Data has been written successfully"); } } }

In file included from iofunctions.c:23:0: iofunctions.h:19:30: error: array type has incomplete element type int readfile( struct pokemon pokearray[ ], int* num, char filename[ ] ); iofunctions.h:19:22: warning: 'struct pokemon' declared inside parameter list [enabled by default] int readfile( struct pokemon pokearray[ ], int* num, char filename[ ] ); iofunctions.h:19:22: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default] iofunctions.h:20:31: error: array type has incomplete element type int writefile( struct pokemon pokearray[ ], int num, char filename[ ] ); iofunctions.h:20:23: warning: 'struct pokemon' declared inside parameter list [enabled by default] int writefile ( struct pokemon pokearray[ ], int num, char filename[ ] ); iofunctions.c: In function 'readfile': iofunctions.c:52:4: error: ISO 690 forbids mixed declarations and code [-Wpedantic] int count =0; /*denotes number of pokemons*/ iofunctions.c:62:25: error: 'struct pokemon' has no member named 'data' pokearray[count-1].data=data; /*store the data in array*/ iofunctions.c: In function 'writefile': iofunctions.c:80:4: error: 'for' loop initial declarations are only allowed in 099 mode for (int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!