If I want to read a string from an arbitrary length from the command line, what is the best way to do this?
I am currently doing this:
char name_buffer [ 80 ]; int chars_read = 0; while ( ( chars_read < 80 ) && ( !feof( stdin ) ) ) { name_buffer [ chars_read ] = fgetc ( stdin ); chars_read++; }
But what should I do if the string is longer than 80 characters? Obviously, I could just initialize the array with a large number, but I'm sure there should be a better way to give the array more space using malloc or something else?
Any tips would be great.
source share