I\'m writing a piece of code in C that iterates T times and each time takes as input the text of a little song on which it will perform some counting operation (counting the len
There's a \n left in the input buffer. One solution is:
#include
#include
#include
#define MAX_SONG_SIZE 501
int main(void){
int t;
scanf("%d", &t);
getchar();
char song[MAX_SONG_SIZE];
while(t--){
fgets(song, MAX_SONG_SIZE * sizeof(char), stdin);
printf("foo\n");
}
return 0;
}
See also: How to clear input buffer in C?