Hey,
I have shorten my code, so that is doesn't consumes much time.Code:/* *Database for storing music cd. */ #include<stdio.h> #define MAX 200 //max characters a user can enter /*prototypes*/ void write_record(void); int file_exists(void); void file_new(void); void file_open(void); /*structure for music cd*/ typedef struct cd { char title[MAX]; char artist[MAX]; int tracks; int album; float price; struct cd *next; }cd; /* Global Variables: */ cd *head = NULL; // a pointer that points to start of the cd node. cd *curr; // pointer that point to current cd node int changes = 0; // boolean: if changes made or not char fname[MAX]; // stores a name of a file. /*function that shows up on exit*/ void quit(void) { printf("\nThank you for using database\n"); system("pause"); } /*Function to see if a file exists*/ int file_exists(void) { FILE *fptr = fopen(fname,"rb"); //open a file for reading. if(fptr == NULL) //if file does not exists return 0. return 1; else //if file exists: { fclose(fptr); //close file return 0; //return 1. } } int main(void) { int choice; //variable that will store choice which the user enters void (*funcPtr)(void); //a pointer to a function that takes no arguments nor returns anything atexit(quit); //calls 'quit' function b4 program exits /*Loop that will only break on exit*/ for(;;) { printf("\nCurrent file open: %s\n",fname); // print current file opened /*print menu*/ puts("\nMenu: \n"); puts(" 1. File new"); puts(" 2. File open"); puts(" 3. Write a record"); puts(" 4. Delete a record by number"); puts(" 5. Delete a record by title"); puts(" 6. Save records"); puts(" 7. Save records with a new file name"); puts(" 8. Edit a record"); puts(" 9. Delete a file"); puts(" 10. Exit"); scanf(" %d",&choice); //ask user for choice switch(choice) { case 2: file_open(); break; case 10: exit(0); break; } } } void file_open(void) { /*check if there are changes and then see if a the user wants to discard the records*/ if(changes && yesno("Are you sure you want to discard the records?")) { return; } /*ask the user the file name they would like to open*/ printf("Enter the file name you would like to open: "); scanf (" %s",fname); /*check if the file exists*/ if(file_exists == 1) { printf("File does not exists!\n"); fname[0] = '\0'; return; } }
Why is it giving me an error saying "comparison between a pointer and integer" when I am doing "if(file_exists == 1)" ?
And its not working.