string parsing and substring in c
- by Josh
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.