1) Why it straight away end the loop after I used getchar() rather than system("pause")?Code:do { // display title printf("Individual Salesman Commission\n"); printf("==============================\n"); // show tip for first input if (*tip == 1) { // display tip printf("Tip: Just input the number instead of the whole id.\n\n"); } // prompt and read salesman id printf("Salesman ID (NO.): "); // if it is not a valid input if (scanf("%d",&stop) == NULL) { valid = 0; // continue loop process printf("Invalid input. Please input again.\n\n"); //system("pause"); // freeze display message printf("\nPress Enter to continue...\n"); getchar(); getchar(); // prompt user } else valid = 1; // end loop process // clear input buffer while ((ch = getchar()) != '\n' && ch != EOF); // clear screen display system("cls"); } while (valid == 0); // loop if the input is invalid
2) How can I validate number+character/string such as 1asd?