Here is an example using strok which saves 3 pointers. Note that these are just pointers to places within the original string, ie if you change the original string you will be changing what they are pointing to as well.
Code:
#include <string.h>
#include <stdio.h>
int main(void)
{
char s[] = "p1 23 5a5";
char * tok[3], * p;
int i;
p = strtok(s," ");
for (i = 0; p && i < 3; i++) {
tok[i] = p;
p = strtok(NULL," ");
}
if (i < 3) {
fprintf(stderr,"Missing parameters\n");
return -1;
}
return 0;
}
You could then check each token for what it should be... here is a simple routine you could use to check a string against any is*() function:
Code:
int checkstr(const char * s, int (*func)(int))
{
int r = 1;
if (s)
while (*s)
if (!(r = func(*s++)))
break;
return r;
}
You would then call it like so: checkstr(string,isalpha) or checkstr(string,isdigit)