i am trying to code a program that will read the last line from a file using c language. i got no experience with c, so my code is giving me plenty of errors. could you help me debug ??
but there is still a problem, your code is giving me error for the following line " int last = ftell(fp)", it says " int not expected ". how could it be when ftell returns a long ?
Actually It is working fine in my environment .
I think it could be , because of different type of data types.
ftell return long , But I stored in int . You change the data type of
first , last variable into long date type , It will work.
minix can be very annoying sometimes ! i have changed both last and first into long. but, it's still giving me the same error. now it says " long not expected "
Might be a strange idea, but try changing the comments started by // into /* */ comments, eg
to
The reason is this: correct ANSI C doesn't support the double-slash comments, since those were originally introduced by C++. So if your compiler is very strict about this (and you being on Minix this might well be) it will fail on those.
i am trying to code a program that will read the last line from a file using c language.
fseek is used for binary files to change the file position indicator in the stream, to read the last line you can simply read the file untill EOF with fgets.