473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to parse this string into a list structure?

I am expecting a string of this format:

"id1:param1,param2;id2:param1,param2,param3;id "

The tokens are seperated by semicolon ";"

However each token is really a struct of the following format:

struct mst_
{
int id;
struct params_* parms ; //0 or more
struct mst_ *next ;
};
where:

struct params_
{
float argval;
struct params_ * next;
};
Nov 7 '08 #1
1 4138
On Fri, 07 Nov 2008 02:36:04 +0000, "(2b|!2b)==?"
<vo*******@ursa-major.comwrote:
>I am expecting a string of this format:

"id1:param1,param2;id2:param1,param2,param3;id "

The tokens are seperated by semicolon ";"

However each token is really a struct of the following format:

struct mst_
{
int id;
struct params_* parms ; //0 or more
struct mst_ *next ;
};
where:

struct params_
{
float argval;
struct params_ * next;
};
Try to remember to put the question ( How to parse this string into a
list structure?) in your text, not just in your subject.

With regard to parsing: If you are ABSOLUTELY certain all the strings
are well formed and if the string is modifiable, you could use strtok.
If either of the previous conditions is false, or if you think you
might need to reprocess the string, or if you just don't like strtok,
you could use strchr to find your separators and sscanf to extract the
fields of interest. If there is a possibility that some of the fields
will contain invalid data, you might want to convert each field into a
string and use the appropriate strto_ functions which will let you
check for errors. (Not part of your question but why is argval a
float and not a double?)

With regard to the linked list: If you KNOW the maximum number of ids
and the maximum number of total parameters, you could define an array
of struct mst_ and an array of struct params_, each with the required
number of elements, and set the pointers to the address of each
element as appropriate. If you don't know the maximums or if the
numbers are potentially larger than you want to define arrays for, you
can use malloc to allocate space for each structure as you decide you
have something to store in it. In either case, algorithms for
chaining nodes to a linked list are mostly language independent
(consequently slightly off topic) and can be found in almost any data
structures text. Implementations of these algorithms have been
discussed repeatedly in this newsgroup (google is at least one source
of archived messages).

--
Remove del for email
Nov 7 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nitin Madnani | last post by:
Hi Guys I am using pyparsing to parse transformation rules for my natural language processing application. The rules also have structure to them, i.e., a rule might look like: ] <--> ] ...
2
by: N | last post by:
Hi, I would like to parse out each value that is seperated by a comma in a field and use that value to join to another table. What would be the easiest way to do so without having to write a...
3
by: IWP506 | last post by:
Hey, I have a lot of common things I want to be included on different pages (i.e. the page title, the header, some buttons and such, etc.). So I was thinking of putting things like...
19
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
6
by: giannik | last post by:
I have an Enum Structure Public Enum MyEnum EnumVal1=0 EnumVal2=1 EnumVal2=2 end enum I save in an access database this enum value as an integer (0=EnumVal1,
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
2
by: shapper | last post by:
Hello, I have the following class ( Level is just a simple enumeration ): public class Theme { public Subject Subject { get; set; } public List<LevelLevels { get; set; } public string Note {...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.