Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C code to read last line from a text file

Status
Not open for further replies.

shan14

Member level 3
Joined
Aug 18, 2014
Messages
61
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
393
Hi

I have to write some data into text file. The data is some thing like this

Integer: 1107, float: 53.141590,A character: s
Integer: 1109, float: 53.141591,A character: c
Integer: 1110, float: 53.141593,A character: f
Integer: 1111, float: 53.141594,A character: B

Now After writing this into the text file; I have to read the last line from that text file and display it.

I having problem in reading the last line, because all int,float,char are present. I don't know How to read all that at once??

I just want the last line as the output.
i.e. Integer: 1111, float: 53.141594,A character: B

so can anyone help me with C code?
 

To extract lines of formatted text, you don't care for the content, just scan for <CR><LF> (dos/windows) respectively <LF> only (unix/linux files). If you don't scan the complete file, make an assumption about maximum line length, read a block starting n characters before the file end until the end, reverse scan the block for line formatting characters.
 

Hello!

Is this code running on a microcontroller?
Is it a plain C program on a PC?
In the latter case, you can use simple stdio functions such as scanf.

Dora.
 

Hi

Thanks for your replies, it was very helpful
Now I have problem with writing into text file.

I have to take values from user. values are in the format
107 53.14 sdf
154 45.32 adsf ............... so on
suppose 10 values

Now I have to write these values into text file .
So, how to write these values which are taken from user into text file.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top