Question: CAN SOMEONE FIX MY ERROR? THIS IS MY CODE IOFUNCTIONS.C: int max_size; int readfile(struct pokemon pokearray[],int *num,char filename[]) { FILE *fptr; //file pointer //initialize the
CAN SOMEONE FIX MY ERROR?

THIS IS MY CODE IOFUNCTIONS.C:
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; /umber attached to each pokemon char name[50]; /ame 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 } 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 } 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"); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
