Very frustated person needs help to create a menu which will read the first last next and previous line from a text files
Anyhelp will be much appreciated
cheers
Bazza
Very frustated person needs help to create a menu which will read the first last next and previous line from a text files
Anyhelp will be much appreciated
cheers
Bazza
Hint: check the manual pages for fseek, fgetpos and fsetpos
>Hint: check the manual pages for fseek, fgetpos and fsetpos
Hint: This is more difficult than you think because the file positioning functions are very restricted for text files.
-Prelude
My best code is written with the delete key.
You're right, sorry Bazza.Originally posted by Prelude
>Hint: check the manual pages for fseek, fgetpos and fsetpos
Hint: This is more difficult than you think because the file positioning functions are very restricted for text files.
-Prelude
I might be wrong on this but can't you just read the text file, count the number of lines you have and keep track of where you currently are with an int. If you store the file in an array it should be pretty easy to navigate back and forward. I am at work now so I can't really produce any code.
>I might be wrong on this but can't you just read the text file,
>count the number of lines you have and keep track of where
>you currently are with an int.
That is one possibility, though a linked list would really be easiest. You would have a pointer to the first and last nodes, and if it were a double linked list then retrieving the previous and next lines would be child's play.
-Prelude
My best code is written with the delete key.
>>That is one possibility, though a linked list would really be easiest. You would have a pointer to the first and last nodes, and if it were a double linked list then retrieving the previous and next lines would be child's play. <<
Sounds like something that will work and not be complicated at all. And a doubly linked list sounds cleaner then my first thought about an array
.
Thanks this actually relates to the chocolate bannanas topic I got my code to read all the lines one after the other. But I needs to navigate.
i need also to identify each field individually
surname,name,id,DOB
heres the code but this is pants
#include <stdio.h>
main()
{
char line[40];
FILE *inp_file;
inp_file = fopen ("records.dat","r");
}
while (inp_file == NULL);
fgets (line, 40, inp_file);
while (feof (inp_file)==0)
{
printf ("%s",line);
fgets (line,40,inp_file);
getchar() ;
}
fclose (inp_file);
}