I\'ve looked everywhere for an answer to my question, but I have yet to find a solid answer to my problem.
I\'m currently in the process of writing a program in C, s
If you are using a gnu system, use the gnu getline extension to the c library, it does all the dynamic sizing for you.
e.g. (though I haven't tested)
void get_command()
{
/*
* Reads in a command from the user, outputting the correct response
*/
size_t buffer_size = 0;
char *command = NULL;
ssize_t len = getline(&command, &buffer_size, stdin);
if(len < 0)
{
perror("Error reading input");
}
else if (command[len - 1] == '\n')
{
puts("It's inside the buffer.");
}
else
{
puts("It's not inside the buffer.");
}
free(command);
}