Hi there,

I'm working on my contact list program and I've got to the point where I can add contacts with name(s), email and phone to a data file (in that order). For example ./addcontact John Baker [email protected] 0211023090 will add that to a line in my contactlist.dat file with spaces in between the arguments. However I am required to have these contacts numbered. So if I was to add multiple contacts they would be listed like so:

1 John Baker [email protected] 0211023090
2 Ben Parker [email protected] 29347728
3 Mary Beans [email protected] 2342342

and so on...

My question is how do I write my program to set the contact number before writing to the file? Later on when I write a program to remove a contact, say contact 2 the data file will have:

1 John Baker [email protected] 0211023090

3 Mary Beans [email protected] 2342342

so when I add a new contact, I want the program to assign the next contact with number 2. Is there a way that I can open and read the contact list line by line searching for a break in the numbering to get a number, otherwise assign the next number after the last contact?

Thanks heaps,
Aonghas