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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
uri22,
Some of these questions have been open for some time. Please resolve them appropriately as soon as possible.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11472178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004239
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20009924
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20011525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20053971
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20078995
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20138023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20149761
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004907
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20079637
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20178804
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20231068
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174847
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20015649
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Some of these questions have been open for some time. Please resolve them appropriately as soon as possible.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11472178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004239
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20009924
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20011525
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20053971
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20078995
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20138023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20149761
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20004907
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20079637
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20178804
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20231068
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174847
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20015649
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
ASKER
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