fgets() and Ctrl+D, three times to end?
问题 I don't understand why I need press Ctrl + D for three times to send the EOF. In addition, if I press Enter then it only took one Ctrl + D to send the EOF. How Can I make the change so that only took one Ctrl + D then it can detect the EOF? #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUF_SIZE 1024 int main(){ char buffer[BUF_SIZE]; size_t msgLength = 1; char *msg = malloc(sizeof(char) * BUF_SIZE); msg[0] = '\0'; printf("Message: "); while (fgets(buffer, BUF_SIZE, stdin)