Trying to take two inputs, an integer value and then a line of characters, using scanf/getline respectively. Problem is that this doesn't seem to work. In this order, the program takes the int input then seems to skip right over the getline.
int n;
char* temp;
int size = 100;
temp = (char*) malloc(size);
scanf("%d", &n);
getline(&temp, &size, stdin);
But if I swap their positions, thusly:
int n;
char* temp;
int size = 100;
temp = (char*) malloc(size);
getline(&temp, &size, stdin);
scanf("%d", &n);
they both work! Is this something dumb I'm doing, some bizarre compiler issue, or what? Ideally I'd like to get the first order working properly, and I can't see why it isn't. Any enlightenment offered would be gratefully received.
This post has been edited by Maynia: 02 March 2012 - 05:08 PM

New Topic/Question
Reply




MultiQuote






|