prompting to enter a name in a loop skips the name enter part
Code:
/* Prompt user for the employees name, hours worked, and hourly rate */
for (x = 0; x < num_emp; x++)
{
printf ("Enter the name for employee #%i: ", x + 1);
gets (emp_name);
printf ("Enter the number of hours employee #%i worked: ", x + 1);
scanf ("%i", &hours_worked);
printf ("Enter the hourly rate of employee #%i: ", x + 1);
scanf ("%i", &hourly_rate);
}
basically in the ouput it skips the enter name for employee n part and goes right to enter the number of hours employee n worked.
i know i am absolutely not suppose to use the gets() function so i think that might be part of my problem. but i need to enter a full name (like John Smith) so i dont think i can use scanf because it will stop at the first space.
so what can i do to modify my code so it will correctly prompt for the entering of the name and will hold both the first and last name.
when i used scanf to enter the whole name, if i put just the first name it worked fine. if i entered a whole name (with a space) the entire program would jumble up and skip to the last employees info being entered from that array.
help is awesome!