Question: Hello again, Im working on a dogdatabase , i need to implement the following into my C Program, I will be using a Xcode to

Hello again, Im working on a dogdatabase, i need to implement the following into my C Program, I will be using a Xcode to compile this.

I keep getting errors about the size of the fwrites in my program like the following, saying they execpt 4 arguements but there is only three:

fwrite(sizeof(struct dog_entry), 1, f);//save the data

My program so far:

// // // Exercise1 // Evan Horvath #include #include #include #define SZ_NAME 32 #define SZ_BREED 32 #define SZ_COLOR 16 #define SZ_SEX 8

struct dog_entry { char name [SZ_NAME]; char breed [SZ_BREED]; char color [SZ_COLOR]; float weight; int age; char sex [SZ_SEX]; };

#define REC_SIZE sizeof(struct dog_entry)

char pr_menu(void); void addRecord(struct dog_entry *reg, int type); void modifyRecord(int); void delete_dog(int g, struct dog_entry *rec); void view_dog(int, struct dog_entry *reg); int find_dog(int, struct dog_entry *rec); void searchRecord(int, struct dog_entry *rec);

int main() { struct dog_entry reg; int i = 0, n; while(free) { char ch = pr_menu(); switch(ch) { case '1': addRecord(®, 1); i++; break; case '2': addRecord(®, 2); break; case '3': delete_dog(1, ®); break; case '4': view_dog(1, ®); break; case '5': searchRecord(n, ®); break; default: break; } if (ch == '6') // exit break; } // system("pause"); } char pr_menu(void) { char ch; // system("cls"); printf(" Menu: 1.Add 2.Change 3.Delete 4.View 5.Search 6.Exit Enter Choice: "); scanf("%c", &ch); return ch; } //Function that adds a record void addRecord(struct dog_entry *rec, int type) { FILE * f; f = fopen("database_dog.txt", "w+");//definition of file // system("cls"); printf("Add the Dog: "); printf(" Enter Name: "); scanf("%s", rec->name); printf(" Enter Breed: "); scanf("%s", rec->breed); printf(" Enter Color: "); scanf("%s", rec->color); printf(" Enter Weight: "); scanf("%f", &rec->weight); printf(" Enter Age: "); scanf("%d", &rec->age); printf(" Enter Sex: "); scanf("%s", rec->sex); fseek(f, 0, SEEK_END); fwrite(sizeof(struct dog_entry), 1, f);//save the data fclose(f);//close the file printf(" "); // system("pause"); } //Function that modifies the record void modifyRecord(int index) { } //Function that displays records void view_dog(int total, struct dog_entry *rec) { FILE * f; f = fopen("database_dog.txt", "r+");//definition of file char name [SZ_NAME]; // system("cls"); printf("View the Dog: "); printf(" Enter Dog's Name: "); scanf("%s", name); rewind(f); while(fread(sizeof(struct dog_entry), 1, f)) { if(strcmp(name, rec->name) == 0) { printf(" Name: %s", rec->name); printf(" Breed: %s", rec->breed); printf(" Color: %s", rec->color); printf(" Weight: %f", rec->weight); printf(" Age: %d", rec->age); printf(" Sex: %s", rec->sex); printf(" "); // system("pause"); break; } } fclose(f);//close the file } int find_dog(int g, struct dog_entry *rec){ FILE * f; f = fopen("database_dog.txt", "r+");//definition of file char name [SZ_NAME]; printf(" Enter Dog's Name: "); scanf("%s", name); rewind(f); int c; while((fread(sizeof(struct dog_entry)), 1, f)) { if(strcmp(name, rec->name) == 0) { c++; break; } } fclose(f);//close the file return c; } void delete_dog(int g, struct dog_entry *rec){ FILE * f; f = fopen("database_dog.txt", "r+");//definition of file char name [SZ_NAME]; int num = 0; int c; // system("cls"); printf("Delete Record: "); printf(" Enter Dog's number: "); scanf("%d", &num); fseek(f, num * sizeof(struct dog_entry), SEEK_SET); fread(sizeof(struct dog_entry), 1, f); fclose(f);//close the file } //Function that searches for the record void searchRecord(int n, struct dog_entry *rec) { int flag = 0; flag = find_dog(0, rec); if(flag == 1) printf("Record exists "); else printf("No such record exists "); }

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!