Sounds like a "state machine". The idea is you step thru the data a byte at a time, and use a variable to keep track of what's happening.
[edit: This is for extracting data from the string. You can use a similar method if you are just counting different kinds of items, see the next few posts.]
Code:
#include <stdio.h>
enum {
NONE,
NUMBER,
WORD,
};
int main() {
int state = NONE;
char input[] = "one 234 @#$garbage!! five 17\t okay",
*p = input, *start = NULL;
while (*p) {
if (state == NONE) {
if (*p >= '0' && *p <= '9') state = NUMBER;
else if ((*p >= 'a' && *p <= 'z')
|| (*p >= 'A' && *p <= 'Z')) state = WORD;
start = p++;
continue;
}
if (*p <= ' ' && start) {
*p = '\0';
if (state == NUMBER)
printf("number: %s\n", start);
else printf("word: %s\n", start);
state = NONE;
}
p++;
}
if (state == NUMBER)
printf("number: %s\n", start);
else if (state == WORD) printf("word: %s\n", start);
return 0;
}
That probably needs some elaboration, eg, notice it handles one kind of mistake but not another:
word: one
number: 234
word: garbage!!
word: five
number: 17
word: okay
Hopefully the basic idea is clear. You need to understand ASCII for this:
http://www.asciitable.com/