Thank you guys. I have the program working now. I wrote a function that I'd like to use to accept user input, but I'd like to get an opinion of someone more experienced.
Here goes...
Code:
void gstring(char *string, int string_length)
{
char buffer[BUFSIZ];
int counter;
fgets(buffer, BUFSIZ, stdin);
for(counter = 0; counter < string_length; counter++)
string[counter] = buffer[counter];
string[string_length - 1] = '\0';
}
usage...
Code:
char sentance[20];
gstring(sentance, 20);
So basically if I only want 20 characters to be read, it'll read just the 20.. but not leave anything standing around in stdin.
I would like to have a function that's universal to strings that use arrays to allocate the memory and strings that use malloc() or some other memory allocation function to allocate the memory.
like if I were to do the following...
Code:
char *string;
string = malloc(80 * sizeof(char));
how could I just get 80 characters or less without leaving anything in stdin?
Thank you all again for reading this (long) post. I find all this "extra characters waiting in stdin" to be very troublesome and confusing.