Originally Posted by
SDH
Yes it should be an array, but I am looking for it be an array of either a letter or number.
Probably the easiest way is to make an array of strings. If the string contains "123" then it is a number. If the string contains "a" for example, then it is a letter. This is sometimes called duck-typing.
Code:
int main(void)
{
char buf[5][BUFSIZ];
strcpy(buf[0], "123");
strcpy(buf[1], "a");
strcpy(buf[2], "-12738");
strcpy(buf[3], "G");
strcpy(buf[4], "");
for (int i=0; i < 5; i++) {
int num;
char c;
if (sscanf(buf[i], " %d ", &num) == 1)
printf("buf[%d] contains an integer: %d\n", i, num);
else if (sscanf(buf[i], " %1c ", &c) == 1)
printf("buf[%d] contains a letter: '%c'\n", i, c);
else
printf("buf[%d] contains a value of unknown type\n", i);
}
}