I need to write a program that takes input line at a time and output only the lines that have two tokens. Assume input is no longer than 50 bytes. I used fgets to capture one line at a time and used sscanf to grab token at a time and see if it returns 2. However, it doesn’t seem to work. Can someone suggest how to do it?
#include <stdio.h>
int main(void)
{
char buff[50];
char token[50];
int number;
while (fgets(buff, sizeof(buff), stdin) != NULL)
{
while ((number = sscanf(buff, "%s", token)) != EOF)
{
number = sscanf(buff, "%s", token);
if (number == 2)
{
printf("%s\t", token);
}
}
}
return 0;
}
This works..