string parsing and substring in c
Posted
by Josh
on Stack Overflow
See other posts from Stack Overflow
or by Josh
Published on 2010-04-25T15:19:18Z
Indexed on
2010/04/25
15:23 UTC
Read the original article
Hit count: 243
I'm trying to parse the string below in a good way so I can get the sub-string stringI-wantToGet
:
const char *str = "Hello \"FOO stringI-wantToGet BAR some other extra text";
str
will vary in length but always same pattern - FOO and BAR
What I had in mind was something like:
const char *str = "Hello \"FOO stringI-wantToGet BAR some other extra text";
char *probe, *pointer;
probe = str;
while(probe != '\n'){
if(probe = strstr("\"FOO")!=NULL) probe++
else probe = "";
// Nulterm part
if(pointer = strchr(probe, ' ')!=NULL) pointer = '\0';
// not sure here, I was planning to separate it with \0's
}
Any help will be appreciate it.
© Stack Overflow or respective owner