Я написал следующий код для чтения строки из окна терминала, проблема в том, что код застревает в бесконечном цикле. Строка/предложение имеет длину undefined, поэтому я планирую прочитать ее по частям в буфер, а затем объединить ее в другую строку, которая может быть расширена с помощью realloc
соответственно. Пожалуйста, кто-нибудь может заметить мою ошибку или предложить лучший способ достичь этого?
#include <stdio.h>
#include <string.h>
#define BUFFERSIZE 10
int main (int argc, char *argv[])
{
char buffer[BUFFERSIZE];
printf("Enter a message: \n");
while(fgets(buffer, BUFFERSIZE , stdin) != NULL)
{
printf("%s\n", buffer);
}
return 0;
}