| tambun (10) | |
|
i have a problem with my C coding...everytime i run the program...it will skip certain line and i can't enter my input for that line...here is my coding look like.. /*Name : Matric num : Lab Group : 1b Purpose : Hand on test*/ #include <stdio.h> //header #include <stdlib.h> int main() { //applicant information char name[30]; char faculty[30]; char matric_no[20]; char date[10]; char vehicle[20]; char destination[50]; char travelling_purpose[50]; int time1, time2, number_passengers; int mobile_no, total_hours; printf("Please enter your name : "); gets(name); printf("\nPlease enter your faculty name : "); gets(faculty); printf("\nPlease enter your matric number : "); scanf("%s", &matric_no); printf("\nDate : "); scanf("%s", &date); printf("\nPlease enter your mobile number : "); scanf("%d", &mobile_no); //booking information printf("\nType of vehicle : "); scanf("%s", &vehicle); printf("\nBooking Date : "); scanf("%s", &date); printf("\nBooking time (24hours) from : "); scanf("%d",&time1); printf(" \t\t\tto : "); scanf("%d",&time2); printf("\nDestination : "); gets(destination); printf("\nTravelling Purpose : "); gets(travelling_purpose); printf("\nNumber of passengers : "); scanf("%d",&number_passengers); total_hours= time2-time1 ; //printf("Total hours : %d", total_hours); printf("\t\t\tSTUDENT VEHICLE BOOKING FORM\n"); printf("================================================================================"); printf("\nAPPLICANT INFORMATION"); printf("\n================================================================================"); printf("\nName : %s", name); printf("\t\t\t\tMatric Number : %s\n", matric_no); printf("\nFaculty : %s", faculty); printf("\t\t\t\tMobile Number : %d\n", mobile_no); printf("\nDate : %s\n\n", date); printf("================================================================================"); printf("\nBOOKING INFORMATION"); printf("\n================================================================================"); printf("\n\nType of vehicle : %s", vehicle); printf("\n\nBooking Date : %s", date); printf("\n\nBooking Time from>>> %d hour", time1); printf(" to>>> %d hour", time2); printf("\n\nTotal booking time : %d hour", total_hours); printf("\n\nDestination : %s", destination); printf("\n\nTravelling Purpose : %s", travelling_purpose); printf("\n\nNumber of passengers : %d", number_passengers); return 0; } if i run this coding...it will not read the destination part...can anyone give a hand?..thank you.. | |
|
|
|
| bobdabilder (56) | |
|
How about instead of gets() Scanf("%s",&destination); | |
|
|
|
| freddie1 (769) | |
| These problems usually involve satisfactorily flushing the keyboard buffer. I'll work on it a bit and see if I can fix it. Bobdabilder's suggestion is worth a try too. | |
|
|
|
| freddie1 (769) | |||
I got this to work ...
Do a search on ... "How To Flush The Keyboard Typeahead Buffer." | |||
|
|
|||
| tambun (10) | |
| awesome!!!..thanks guys... | |
|
|
|
| bobdabilder (56) | |
|
You also may want to look at fgets(). fgets(name,30-1,stdin); for example. | |
|
|
|