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
sounds like homework, so no-one will post code (anyone who does is at risk of having his account cancelled.
As a hint, however, you need to use strtok() Look in your help files. Call strtok() in a loop. That's it really, nothing difficult.
btw, if it's not homework & your parsing a program'S command line, look into getopt()
As a hint, however, you need to use strtok() Look in your help files. Call strtok() in a loop. That's it really, nothing difficult.
btw, if it's not homework & your parsing a program'S command line, look into getopt()
ASKER
graham_k
BTW, THIS IS NOT HOMEWORK !!!!!!!
It is a part of a very big project I'm working on right now.
I thought I can use some help from the experts.
The name of this site is experts exchange, isn't it what it meant for?
Thanks.
uri22
BTW, THIS IS NOT HOMEWORK !!!!!!!
It is a part of a very big project I'm working on right now.
I thought I can use some help from the experts.
The name of this site is experts exchange, isn't it what it meant for?
Thanks.
uri22
Are you still looking for an answer?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of 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
Do you want any arbitrary structure from your program to be filled with this function? If that's what you want you will probably fail to do that - this will require dynamic type detection, which is not available in C.
In any case your example is wrong as well - you will fail to fill 'char' struct member paramX with strings (or numbers?) "123" or "USD" - you should use char* or char[XX] to store that.