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.

How can I extract data and load into variables from a string.

Status
Not open for further replies.

ahmad2005

Member level 1
Joined
Mar 30, 2011
Messages
40
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Mirpur,Dhaka,Bangladesh
Activity points
1,618
I'm a getting string line from a serial output. Now I wanna extract this string and load the substrings into the different variables. How can I do this?
For example, I have a string line something like "=>Data1=10&Data2=20&Data3=30". Now I wanted to load these data values into three variable like variable1=10, variable2=20, and variable3=30.

How could be the best way to do this. Can anyone give me an example code in C ?
 
Last edited:

Look at the 'strtok' function. It is for searching for characters throughout a string and dividing it at that point (Tokenizing). If you loop the function until it returns nul (meaning it has reached the end of the string) and use '=' as the search character it will return a pointer to each of the values in turn, no matter how long the string is.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top