Question

Please, please help with C program.

This is a longer program, so take your time. But please make sure it meets all the requirements and runs.

Here is the assignment:

In this exercise you are to create a database of dogs in a file, using open, close(), read, write(), and Iseek(). Do NOT use

#define SZ_BREED 32 #define SZ_COLOR 32 struct dog_entry { char name (SZ_NAME]; char breed (SZ_BREED]; char color (SZ_COLOR];

You should implement all of the following functions (with suggested prototypes): unsigned char pr_menu(void); void add_dog(in

The add dog and change dog options should use add_dog function to prompt the user for the contents of a dog_entry record and

I appreciate any help given.

Cannot use goto or system(3) function unless directed to.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Files

filename: main.c

#include <stdio.h>

#define SZ_NAME 32
#define SZ_BREED 32
#define SZ_COLOR 16

struct dog_entry
{
char name[SZ_NAME];
char breed[SZ_BREED];
char color[SZ_COLOR];
unsigned short weight;
unsigned char age;
char sex;
};

#define REC_SIZE sizeof(struct dog_entry)

void print_dog(struct dog_entry *dp)
{
printf("DOG RECORD:\n");
printf("\tNAME: %s\n", dp->name);
printf("\tBREED: %s\n", dp->breed);
printf("\tCOLOR: %s\n", dp->color);
printf("\tWEIGHT: %d\n", dp->weight);
printf("\tAGE: %d\n", dp->age);
printf("\tSEX: %c\n", dp->sex);
}
#include <stdio.h> #define SZ_NAME 32 #define SZ_BREED 32 #define SZ_COLOR 16 struct dog_entry char name[SZ_NAME]; char breed

filename: my_utilities.h

/*
my_utilities.h
*/

#include <stdio.h> // printf, perror
#include <fcntl.h> // open

#define _DBG_(fmt_str, value) printf("[%s:%d: %s = " fmt_str "]\n", __FILE__, __LINE__, #value, value)
#define DBG_STR(value) _DBG_("\"%s\"", value)
#define DBG_NUM(value) _DBG_("%d", value)
#define DBG_CHAR(value) _DBG_("'%c'", value)

int safe_open(char *, int, int, const char *);
void strip_nl(char *);
size_t read_line(int, char *, size_t);

// Permissions must be specified so that O_CREAT will not throw
// you for a loop.
int safe_open(char *fname, int flags, int permissions, const char *msg)
{
int fd = open(fname, flags, permissions);

if (fd < 0) {
perror(msg);
exit(-1);
}

return fd;
}

void strip_nl(char *str)
{
size_t len = strlen(str);
if (str[len - 1] == '\n')
str[len - 1] = '\0';
}
my_utilities.h #include <stdio.h> #include <fontl.h> // printf, perror 11 12 #define _DBG_(fmt_str, value) printf([%s:%d: %s

filename: dog_entry.h

#include <stdio.h>

#define SZ_NAME 32
#define SZ_BREED 32
#define SZ_COLOR 16

struct dog_entry
{
char name[SZ_NAME];
char breed[SZ_BREED];
char color[SZ_COLOR];
unsigned short weight;
unsigned char age;
char sex;
};

#define REC_SIZE sizeof(struct dog_entry)

void print_dog(struct dog_entry *dp)
{
printf("DOG RECORD:\n");
printf("\tNAME: %s\n", dp->name);
printf("\tBREED: %s\n", dp->breed);
printf("\tCOLOR: %s\n", dp->color);
printf("\tWEIGHT: %d\n", dp->weight);
printf("\tAGE: %d\n", dp->age);
printf("\tSEX: %c\n", dp->sex);
}
#include <stdio.h> m #define SZ_NAME 32 #define SZ_BREED 32 #define sz_COLOR 16 struct dog_entry char name (SZ_NAME]; char br

OUTPUT

ENTER 1 to add,
2 to change,
3 to delete,
4 to view,
5 to search,
6 to exit
ENTER: 1


-ADD DOG RECORD-

-ADD DOG-

Enter the dog's NAME.
ENTER: ALpha
Enter the dog's BREED.
ENTER: Pomerion
Enter the dog's COLOR.
ENTER: Grey
Enter the dog's WEIGHT. [pounds]
ENTER: 10
Enter the dog's AGE. [years]
ENTER: 4
Enter the dog's SEX. [M/F]
ENTER: F


-RECORD TO BE ADDED-

DOG RECORD:
NAME: ALpha
BREED: Pomerion
COLOR: Grey
WEIGHT: 10
AGE: 4
SEX: F
Would you like to save this record to disk? [Y/N]
ENTER: Y


-RECORD SAVED-


ENTER 1 to add,
2 to change,
3 to delete,
4 to view,
5 to search,
6 to exit

=======================================================================

Hope this helps!

Please let me know if any changes needed.

Thank you!

I hope you're safe during the pandemic.

Add a comment
Know the answer?
Add Answer to:
Please, please help with C program. This is a longer program, so take your time. But...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • IN C ONLY As mentioned earlier there are two changes we are going to make from...

    IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...

  • // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given...

    // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...

  • C programming The program will require the following structure: struct _data { char *name; long number;...

    C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...

  • I need help finding what is wrong with this code, it is for a CS course...

    I need help finding what is wrong with this code, it is for a CS course I am taking which codes in C (I am using XCode on Mac to code). This is the assignment: "Write a program that performs character processing on 10 characters read in from a file, and writes the results to output files. The program should read from “input.dat”. The program should write the ASCII values of the characters to “output_ascii.dat”. The program should print statistics...

  • // C code // If you modify any of the given code, the return types, or...

    // C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList {    struct patient *patient;    struct patientList *next; } *list = NULL;  ...

  • The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also...

    The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also please explain why the seg fault is happening. Thank you #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size;...

  • I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves...

    I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...

  • Using the program segment and sample txt file below, write a program that contains a linked...

    Using the program segment and sample txt file below, write a program that contains a linked list of students. The program should allow the user to: 1. initialize list of students 2. add additional student to front of list 3. add additional student to rear of list 4. delete student 5. sort students alphabetically 6. sort students by idNum 7. show number of students in list 8. print students 9. quit program XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The program should be divided into the...

  • // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the...

    // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the compiler used: Visual studio or gcc // READ BEFORE YOU START: // You are given a partially completed program that creates a linked list of patient information. // The global linked list 'list' is a list of patients with each node being struct 'patientList'. // 'patientList' consists of struct 'patient' which has: patient name, room number, and a linked list of 'doctors'. // The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT