Jan 31, 2006 #1 T 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.
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.
Feb 1, 2006 #2 F 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.
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.
Feb 1, 2006 #3 T 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 Isn't there a "scanf" type function to do that
Feb 1, 2006 #4 I IBNobody Junior Member level 1 Joined Jan 22, 2006 Messages 18 Helped 3 Reputation 6 Reaction score 2 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
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
Feb 1, 2006 #5 T 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 Can I write sscanf(string,"\r\n%s:\"%s\"\r\n%s",dummy1,IDstring.dummy2);
Feb 1, 2006 #6 I IBNobody Junior Member level 1 Joined Jan 22, 2006 Messages 18 Helped 3 Reputation 6 Reaction score 2 Trophy points 1,283 Activity points 1,473 Something like that would work. You just need to play around with the format string. - Nobody