There are two kinds of input that can be provided:
50
b 2 40
I have to distinguish both the cases and then take further actions accordingly. Here's what I have tried:
char input[100];
fgets(input, 100, stdin);
printf("%s", input);
int count = 0;
char a[3][100];
int j=0, i=0;
while(true){
a[count][j] = input[i];
j++; i++;
if(input[i] == '\n'){
break;
}
if(input[i] == ' '){
count++;
j = 0;
i++;
}
}
printf("%d\n", count);
printf("%s\n", a[0]);
printf("%s\n", a[1]);
printf("%s\n", a[2]);
For example, input:
b 6767 9090
output:
b 6767 9090
b 6767 9090
2
b����
67670
9090
Can somebody help me on how to do this? I was suggested previously to use fgets. As I am a beginner in C, I am having difficulty figuring out how to achieve this.