Hello there,

Kindly seek your help with a C programming language program that:

1 Reads reads and modify a text fine called mydata.txt
2 In txt file, we must enter the following data : name surname telephone number like this: John West 6976688742
3 The program should be able to fuction the following commands by typing in command screen the following:
p = prints all the registered entries in text file
f West = prints all the line that has as surname equal to West
d West = delete the line that has as surname equal to West
i Peter Smith 69852147 = inserts new line in text file
q = stop the program and update the file with all the amendments that done

4 Print ascending order:
psn = prints in ascending order of names
pss = prints in ascending order of surnames

As i have no expirence with C, all recomendations would be highly appriciated.

Regards

Dani AI

Generated

A compact implementation plan and practical tips that build on original request and 's suggestion to start small. The easiest, safest design is: load the entire file into memory as an array of records, operate on that in-memory list while accepting commands, then rewrite the file when the session ends (or write a temp file and rename whenever you persist changes). Keep phone numbers as strings so leading zeros are preserved and use sized scanf/fgets formats (e.g., "%63s") to avoid buffer overflow.

Command handling and behavior notes:

  • Read each command line with fgets, split the first token (command) and the rest. Implement p (print all), f surname (filter and print matches), d surname (delete — decide whether to remove the first match or all matches and document that choice), i name surname phone (append a new record in memory), q (save and quit), plus psn/pss (sort then print). Use a case-insensitive comparison for surname searches; strcasecmp is POSIX, _stricmp on Windows, or implement a small casecmp helper by lowercasing into temporary buffers. For sorting, use qsort with a comparator that compares name or surname.

Small API sketch (starter prototypes):

typedef struct {
  char name[64];
  char surname[64];
  char phone[32];
} Contact;

Contact *load_file(const char *path, size_t *count);
int save_file(const char *path, Contact *list, size_t count);
int add_contact(Contact **listp, size_t *countp, Contact c);
size_t delete_by_surname(Contact *list, size_t *countp, const char *surname, int delete_all);
void sort_by_name(Contact *list, size_t count);
void sort_by_surname(Contact *list, size_t count);

Cautions: never edit the text file in-place; write to a temporary file and rename to avoid corruption. Validate parsed lines and skip malformed ones with a clear message. Breaking the task into load/save, print, insert, delete, sort — and testing each step — makes this approachable even for a beginner (as noted, it looks big at first, but decomposition makes it manageable).

Recommended Answers

All 2 Replies

Welcome to the forum, Pdoratis! ;)

The thing is, you NEED some experience with C, to work on a C program - that's the simple fact.

We won't just do your assignment for you - especially important is for YOU to put some effort into the start of the job. You know how it goes, a lot of people come here, just looking for free homework programming, and have no intention of working on it.

You need to start the program, and post the program, even if it's not done. Post it. Tell us where you're stumped - with logic or syntax, whatever.

THEN we can be a lot of help, AND you'll learn a lot more than by just having it done for you, without putting any work into the program.

The program you want will take a good deal of time for a raw beginner, so don't put it off.

It seems like a professional program.You are saying you don't have any experience with C,then how can you chose this program to complete.Are you a professional IT person.If it is ,no IT person will be there who doesn't know C.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.