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,805
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.
 

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.
 

Isn't there a "scanf" type function to do that
 

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
 

Can I write

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

Something like that would work. You just need to play around with the format string.

- Nobody
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…