Program not reading fgets at all

Viewed 21
#include <stdio.h>

int main(void) {

    int numWords;
    char str[100];

    printf("Enter how many words:\n");
    scanf("%d", &numWords);

    printf("Enter %d words:", numWords);

    fgets(str, 100, stdin);

    return(0);
}

This program does not read fgets at all. It will print the text and scan what what the user enters into the numWords, but will not read scanf. I have tried putting a newline character after scanf but then the "Enter %d words:" will not print. I would like everything to print in order.

This is just the beginning of a more complex program, not the whole thing.

0 Answers
Related