I have a program which takes in the user input for classroom and time. The classroom input is store inside a char* classroom, and the time is store inside a int time. However, when I run the program, it stops at when I press enter after I have type a classroom. The printf for "Please enter a time: ", did not come out. Why is this so??
void option1()
{
char* classroom;
int time;
printf("Please enter the classroom: ");
scanf_s("%s", &classroom);
printf("Please enter the time: ");
scanf_s("%d", &time);
}
Thanks for help :)
scanf_sworks differently, you're looking forscanf. - user2371524classroomis already a pointer, don't use the&operator here. - user2371524"%s"is a guaranteed buffer overflow, always use a field-width. - user2371524classroomdoesn't point anywhere, you didn't allocate memory for it -> undefined behavior. - user2371524