Help reading from a file in C

I'm trying to write a C program that takes 3 different inputs from the user (name, day, year) and then I fwrite it into a binary file in the following format "Name | day | year". Nothing complicated so far, its just "%s | %s | %s".

However I also want the user to be able to access information from the said binary file. I,e the user can get a list of all the names. How would I go about so that the program reads the binary file and reads the "Name | day | year" and stores each of the elements into an array. (I want it to be an array so I can sort the names alphabetically (but that is another issue).

Writing into the file seems relatively straight forward but I have no idea how to read from the file with the " | " dividing each parameter.

Thanks in advance

Comments

  • Read a line.
    Look for the 1st |
    Take the stuff before it and put it in NAME
    Find the 2nd |
    etc...
  • Im still very new to C. How exactly would I tell the program to take the stream before | and input it in NAME?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories