Problem: after choosing operation, supposedly the user would input a string by calling getString(). But in this case it skips the function where the user input happens and just proceeds calling the function operations.
Anyone has an idea why is this happening?
int main() {
int choose;
char arr[SIZE];
do {
printf("\n\n-----------------------------------\n");
printf("Enter what operation to perform\n");
printf("[1]Ctype Functions\n");
printf("[2]String Functions\n");
printf("-----------------------------------\n\n");
printf("Enter function: ");
scanf("%d", &choose); //choose what operation
char *str = getString(arr); //user input string, also the problem, it skips this part
switch (choose) {
case 1:
printf("\n\n------------------------------------\n");
printf("Function [%d] Selected\n", choose);
printf("------------------------------------\n");
cTypeFunct(str); //calling ctype function operation
getch();
system("cls");
break;
case 2:
printf("\n\n------------------------------------\n");
printf("Function [%d] Selected\n", choose);
printf("------------------------------------\n");
stringFunct(str); //calling string function operation
getch();
system("cls");
break;
}
} while(choose);
return 0;
}
scanfandgetchandgetString.getStringfunction, see if you've got a similarly well-behavedgetIntfunction to go with it. If so, they ought to play well together. While you'e at it, I encourage you to get rid of those extraneousgetchcalls. Those were probably your attempt to get rid of the stray newline characters that are (probably) plaguing you, but they're likely to cause as many problems as they solve, so if you can find a better solution to the stray-newline problem, hopefully you won't need the extraneousgetch's.