Im having a few problems with completeing a adress book program in c (not c++ jus regular c), it requires a minimun of 5 functions so i have decided to use add, search, veiw now in order to complete i wud like to keep the add function but make a new function tht shows that the data is saved to a file, also i wud like to divide my veiw function into 2 seperate function, one being a veiw all and the other being a veiwing a specific name...... Any help wud be greatly appreciated and the sooner is the better...... thanks in advance
(attached is the current state of my problem)

You need to change the file name extension, right off!


1) Dot cpp is the default file extension for C++, so it can cause much confusion and wasted time. Change it to just dot c, and then we're at least running on the same language compiler

2) gets() is very unsafe, since it makes no check on the length of the string it is getting from the user. Use
fgets(bufferName, sizeof(bufferName), stdin), instead.

3) flushing stdin is non-standard and doesn't always work. Use getchar() to pull the newline off the keyboard buffer, as needed.

4) feof() doesn't act as you suspect or hope.
while((fgets(buff, sizeof(buff), fp)) != NULL) { is much better.

where buff is the name of a char array big enough to receive the line of text (all of it).

You haven't said what your problems with coding up these changes are, so I don't know what else to advise, right now.

Once you know how to find and display one record from the file, there's no difficulty in displaying a page full of records at once, prompting the user to hit enter to continue, and displaying the next page of data, until either the end of the file, or the user presses q to quit the display of records.

Programs involve very explicit code and use very exact logic (good or bad, the program uses it). So the more specific your questions are, the better replies you will receive.

Just posting up a program and saying "I want to change this and that and something else", is not going to come off well. You need to put some "skin" into the post, and put up your attempt to write these changes, and when you're stuck, THEN post up specific questions about fixing it.

That's how the forum work best - we can give the best advice because we know the specifics, and it takes far less time and effort. You get the best advice for the problem, because you gave the best description or example of it.

commented: Yes +20