Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

How to decode a text stream in C

Status
Not open for further replies.

techie

Advanced Member level 3
Joined
Feb 5, 2002
Messages
839
Helped
58
Reputation
116
Reaction score
9
Trophy points
1,298
Location
Pakistan
Activity points
7,799
text stream decode

I have a text stream as follows.

Blah blah blah blah ....
Location:"Location Data String"
ID:"ID string"
Parameters:"misc text"
Timer:"12345"
blah
blah
....

I want to read them into string variables like ID = "ID string" etc. Can someone tell me a simple way to do that in C.
 

fdarkangel

Newbie level 6
Joined
Dec 2, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,398
you can use fgets go read a file line by line. then, you can get the word until ':' and choose the appropriate action. for instance, if the first word is ID, then the rest after ':' should be copied to the string id.
 

techie

Advanced Member level 3
Joined
Feb 5, 2002
Messages
839
Helped
58
Reputation
116
Reaction score
9
Trophy points
1,298
Location
Pakistan
Activity points
7,799
Isn't there a "scanf" type function to do that
 

IBNobody

Junior Member level 1
Joined
Jan 22, 2006
Messages
18
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,283
Activity points
1,473
sscanf would work...

It's in stdio.h

<# of items formatted> = sscanf(<source string>, <format string>, <target 1>, <target 2>, ...);

In your case, I think the target string is: "%s:\"%s\""

I could be wrong, though...

- Nobody
 

techie

Advanced Member level 3
Joined
Feb 5, 2002
Messages
839
Helped
58
Reputation
116
Reaction score
9
Trophy points
1,298
Location
Pakistan
Activity points
7,799
Can I write

sscanf(string,"\r\n%s:\"%s\"\r\n%s",dummy1,IDstring.dummy2);
 

IBNobody

Junior Member level 1
Joined
Jan 22, 2006
Messages
18
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,283
Activity points
1,473
Something like that would work. You just need to play around with the format string.

- Nobody
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top