Link to home
Start Free TrialLog in
Avatar of uri22
uri22

asked on

Parsing string function

I need a function that does the follows.
It receives as parameters :
1.string
2.delimiter
3.structure
int parse(char *string, char *delimiter, struct struct)
The function shell parse the string which consists data and delimiters, and transfer the data to the struct members.
The function shell check weather the number of parameters (after parsing the message) is equal to the number of members in the structures and return a proper error if neccessary.
e.g.
struct ur{
char param1
char param2
char param3
}
string : "123,USD,abc,"
delimiter : ,
in this case the outcome of the function will be:
param1=123
param2=USD
param3=abc

Need a working function as an answer
Thanks
uri22
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of uri22
uri22

ASKER

imladris, thanks.
I'm looking for something a litlle more generic, since there are few types of struct with different number of parameters (3,4,5, etc.)
uri22
There is no generic way for a function in C to ascertain the details of the elements of a structure. If you need to handle differing structures, you will have to include some metadata (i.e. data that describes the structure) somewhere. This could be in the arguments to the function, or maybe in the structure itself. If you provide a selection of the different structures that you want to handle I can make a proposal. If it is just differing number of elements/parameters, it might be simplest to just pass in the number of parameters to the function.
This question was LOCKED with a PROPOSED ANSWER and awaits your decision today.  Once a question is LOCKED with a Proposed Answer, few new experts will step in to help on that question, since the assumption is, you've been helped.  If the Proposed Answer helped you, please accept it and award that expert.  If it did not help you, please reject it and add comments as to status and what else is needed.
 
If you wish to award multiple experts, just comment here with detail, I'll respond as soon as possible.  As it stands today, you asked the question, got help and not one expert was awarded for the contribution(s) made.  Your response is needed.  I'll monitor through month end, and if you've not returned to complete this, we'll need to decide.  Expert input is welcome (as always) to determine the outcome here if the Asker does not respond.
 
Your response in finalizing this (and ALL) your question(s) is appreciated.
 
Moondancer
Community Support Moderator @ Experts Exchange

Force/accepted by

Netminder
Community Support Moderator
Experts Exchange