#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUF_SIZE 1024
int main ()
{
char buffer[BUF_SIZE];
int contentSize = 1;
char* content = (char*)malloc(sizeof(char) * BUF_SIZE);
content[0] = '\0';
while(fgets(buffer, BUF_SIZE, stdin))
{
contentSize = contentSize + strlen(buffer);
content = (char*)realloc(content, contentSize);
strcat(content, buffer);
}
return 0;
}
im trying to read in everything entered by the user (even whitespace characters) and i am pretty close to getting it to work but the loop never ends. fgets()
just keeps asking for more input, how do i fix this please.