I'm having issues with my functions working properly. I'm not sure where I'm going wrong with them and if i'm using the correct mode for the fopen. I've hit the wall with where I could be going wrong and tried looking at other posts about files. Any suggestions would be appreciated and thanks in advance!Code:#include <stdio.h> struct hardware{ int recNum; char toolName[30]; int quant; double cost; }; void intializeRecord(); void listUnsorted(); void listSorted(); void saveRecord(); void newTool(); void loadRecord(); void searchTools(); void deleteRecord(); int main(){ int choice; printf("1. Initialize the Database \n"); printf("2 Input New Records \n"); printf("3. Search for a record \n"); printf("4. Delete a Record \n"); printf("5. List all the records \n"); printf("6. List all the records in order of record number\n"); printf("7. Save Database \n"); printf("8. Load an exisiting Database \n"); printf("9. Exit \n"); printf("\n"); printf("\n"); printf("Please enter your choice \n"); scanf("%d",&choice); printf("\n\n"); while(choice != 9){ switch(choice){ case 1: intializeRecord(); break; case 2: newTool(); break; case 3: searchTools(); break; case 4: deleteRecord(); break; case 5: listUnsorted(); break; case 6: listSorted(); break; case 7: saveRecord(); break; case 8: loadRecord(); break; } } return 0; } void intializeRecord(){ int i; FILE *ft; struct hardware blank = {0,"",0,0.0}; if((ft = fopen("hardware.txt","a")) == NULL) printf("File could not be opened. \n"); else{ for(i = 1; i<=100;i++) fwrite(&blank,sizeof(struct hardware),1,ft); fclose(ft); } } void searchTools(){ int recordnumber; int selection; FILE *ft; char name; ft = fopen("hardware.txt","r"); struct hardware tool = {0,"",0,0.0}; printf("1. Search using record number\n"); printf("2. Search using tool name \n"); scanf("%d",&selection); switch (selection){ case 1: printf("Enter the record number of the tool\n"); scanf("%d",&recordnumber); fseek(ft,(recordnumber-1)*sizeof(struct hardware),SEEK_SET); fread(&tool,sizeof(struct hardware),1,ft); if(tool.recNum == 0){ printf("Record Number not found\n"); return; } else{ printf("%-6d%-15s%-11d%10.2f\n",tool.recNum,tool.toolName,tool.quant,tool.cost); } break; case 2: printf("Enter the tool name you wish to search for"); scanf("%s",&name); fseek(ft,(recordnumber-1)*sizeof(struct hardware),SEEK_SET); fread(&tool,sizeof(struct hardware),1,ft); if(tool.recNum == 0){ printf("Record Number not found\n"); return; } else{ printf("%-6d%-15s%-11d%10.2f\n",tool.recNum,tool.toolName,tool.quant,tool.cost); } break; } } void saveRecord(){ FILE *writeptr; FILE *readptr; struct hardware tool = {0,"",0,0.0}; if((writeptr = fopen("hardware.txt","w")) == NULL) printf("Record could not be open. \n"); else{ rewind(readptr); fprintf(writeptr,"%-6s%-15s%-11s%10s\n","Record #", "Tool Name","Quantity","Cost"); while(!feof(readptr)){ fread(&tool,sizeof(struct hardware),1,writeptr); if(tool.recNum !=0) fprintf(writeptr,"%-6d%-15s%-11d%10.2f\n",tool.recNum,tool.toolName,tool.quant,tool.cost); } fclose(writeptr); } } void listSorted(){ FILE *readft; } void listUnsorted(){ FILE *ft; struct hardware tool = {0,"",0,0.0}; if((ft = fopen("hardware.txt","r")) == NULL) printf("Record could not be open. \n"); else{ printf("%-10s%-15s%-11s%10s\n","Record#", "Tool Name","Quantity","Cost"); while(!feof(ft)){ fread(&tool,sizeof(struct hardware),1,ft); if(tool.recNum !=0) printf("%-6d%-15s%-11d%10.2f\n",tool.recNum,tool.toolName,tool.quant,tool.cost); } fclose(ft); } } void loadRecord(){ FILE *ft; char open[100]; printf("Enter the name of the database you wish to load\n"); scanf("%s",&open); ft= fopen(open,"r+"); fclose(ft); } void deleteRecord(){ struct hardware tool, blanktool = {0,"",0,0}; FILE *ft; int recordnumber; ft = fopen("hardware.txt","r+"); printf("Enter the record number of tool you wish to delete (1-100): \n"); scanf("%d",&recordnumber); fseek(ft,(recordnumber-1)*sizeof(struct hardware),SEEK_SET); fread(&tool,sizeof(struct hardware),1,ft); if(tool.recNum == 0){ printf("Account %d does not exist. \n", recordnumber); return; } else{ fseek(ft, (recordnumber-1)*sizeof(struct hardware),SEEK_SET); fwrite(&blanktool,sizeof(struct hardware),1,ft); } } void newTool(){ struct hardware tool = {0,"",0,0.0}; FILE *ft; int recordnumber; ft = fopen("hardware.txt","a"); printf("Enter the new record number (1-100)\n"); scanf("%d",&recordnumber); fseek(ft, (recordnumber-1)*sizeof(struct hardware), SEEK_SET); fread(&tool,sizeof(struct hardware),1,ft); if(tool.recNum != 0){ printf("Record number %d already contains information. \n",tool.recNum); return; } else{ scanf("%s",tool.toolName); printf("Enter the quanity \n"); scanf("%d",&tool.quant); printf("Enter the cost of the tool \n"); scanf("%lf", &tool.cost); tool.recNum = recordnumber; fseek(ft, (tool.recNum -1)*sizeof(struct hardware),SEEK_SET); fwrite(&tool,sizeof(struct hardware),1,ft); fclose(ft); } }