i've done this so far but it either returns all a number or all not a number no matter what input i put in.
Example input output:
Enter string : 1 3 aa +
Output :
1 Number
3 Number
aa Not a number
+ Operator
Code:
# include <stdio.h>
# include <string.h>
# include <ctype.h>
# define STRING 100
# define WORD 4
int val(char tokens[])
{
int i=0;
while ()
{
if(!isdigit(tokens[i]))
{
return 0;
}
i++;
}
return 1;
}
int main(void)
{
char charStr[STRING];
char token[LEN];
char *tokenPtr = token;
int i;
printf("Enter string : ");
if(fgets(charStr, STRING, stdin) != NULL)
{
tokenPtr = strtok(charStr, " ");
while(tokenPtr != NULL)
{
if(val(token) == 1)
printf("%s Number\n", tokenPtr);
else
printf("%s Not a number\n", tokenPtr);
tokenPtr = strtok(NULL, " ");
}
}
return 0;
}