I'm attempting to search for a string in a character array whereby the string to be identified is UCAST and whereby the character array is as follows:
analysis_buffer[0] = \n;
analysis_buffer[1] = U;
analysis_buffer[2] = C;
analysis_buffer[3] = A;
analysis_buffer[4] = S;
analysis_buffer[5] = T;
analysis_buffer[6] = \r;
The code I executed to attempt the search procedure is as follows:
constant char str[] = "UCAST";
char* pch = strstr(analysis_buffer,str);
if (pch!=NULL) {
printf("found at %d\n", pch - analysis_buffer + 1);
pch = strstr(pch+1, analysis_buffer);
} else {
printf("pch :%s\n", pch);
}
NOTE: analysis_buffer is the array I described above.
The problem I'm encountering is that the strstr bit amounts to NULL while it shouldn't. Any ideas?
I've had a look at the following links on stackoverflow for help:
Does char array contain string?
How to search a string in a char array in C?
THANKS
analysis_buffer?