I think you can try something like this.
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
char type1[20];
char type2;
char line[100];
int var_1,var_2;
printf("Enter the line type var1 var2: ");
fgets(line,sizeof(line),stdin);
if (sscanf(line,"%c %d %d",&type2, &var_1, &var_2) == 3 )
{
printf("You passed char as type: %c\n", type2);
} else if (sscanf(line,"%s %d %d",type1, &var_1, &var_2) == 3 )
{
printf("You passed string as type: %s\n", type1);
}
return 0;
}
When I ran it following was the output.
[root@linux-outside snoopy]# ./parse
Enter the line type var1 var2: servo 1 2
You passed string as type: servo
[root@linux-outside snoopy]# ./parse
Enter the line type var1 var2: q 1 2
You passed char as type: q
[root@linux-outside snoopy]#