I'm trying to get 2 more characters after finding the first occurrence with strchr
over a char pointer. The string can look like:
foo;bar;2012 -> should output foo;b
foo;caz; -> should output foo;c
foo; -> should output foo (there are no +2 chars)
foo -> null
For the first case, I figure I can do something like,
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "foo;bar;2012";
char *pch = NULL;
if ((pch=strchr(str,';')) != NULL) {
*pch++;
*pch++;
*pch = '\0';
}
puts(str);
return 0;
}
But what's the proper way of checking if I can advance the pointer within the string without going over?