I'm trying to parse a comma delimited string with strtok -
It's working fine but I have a couple of special cases:
I'm reading from a file and one line of my 320-character string looks like this:
JONES, SMITH, ABBEY, JOHNSON, LONG ISLAND, STATEN ISLAND, ...
My program can handle most of these values but it has a problem with items such as LONG ISLAND.
It treats these as two separate tokens: LONG and ISLAND.
Is there any way to modify my code so I can handle these values?
Here's my code:
-------------------------------------------------
/* declared in main() */
char seps[] = ", ";
char *token;
char req_tmp[320+1];
/* where I read the string from the file */
strcpy(req_tmp, adds.req_by);
token = strtok(req_tmp, seps);
while(token != NULL)
{
strcpy(bp70.last_name,token);
get_mbr_id();
token = strtok(NULL, seps);
}
----------------------------------------------------
I tried different delimiters but because of my file layout, a blank space and then a comma separating each item, it gets confused near LONG ISLAND and treats this as two separate items.
Is there a way to modify my code to correctly parse this field?
Thanks in Advance
John
It's working fine but I have a couple of special cases:
I'm reading from a file and one line of my 320-character string looks like this:
JONES, SMITH, ABBEY, JOHNSON, LONG ISLAND, STATEN ISLAND, ...
My program can handle most of these values but it has a problem with items such as LONG ISLAND.
It treats these as two separate tokens: LONG and ISLAND.
Is there any way to modify my code so I can handle these values?
Here's my code:
-------------------------------------------------
/* declared in main() */
char seps[] = ", ";
char *token;
char req_tmp[320+1];
/* where I read the string from the file */
strcpy(req_tmp, adds.req_by);
token = strtok(req_tmp, seps);
while(token != NULL)
{
strcpy(bp70.last_name,token);
get_mbr_id();
token = strtok(NULL, seps);
}
----------------------------------------------------
I tried different delimiters but because of my file layout, a blank space and then a comma separating each item, it gets confused near LONG ISLAND and treats this as two separate items.
Is there a way to modify my code to correctly parse this field?
Thanks in Advance
John