new input thing that works with spaces too

This commit is contained in:
dvorakmortonxd 2026-05-25 21:53:21 +02:00
commit 26ced52008

8
main.c
View file

@ -131,6 +131,14 @@ int main() {
scanf("%s", fruit); scanf("%s", fruit);
printf("\nYou choose %s as your fruit!", fruit); printf("\nYou choose %s as your fruit!", fruit);
// INPUT (LARGER AMOUNT OF WORDS COMPARED TO SCANF)
printf("\n\nINPUT (larger) BELOW:\n"); // DIVIDER
char vegetable[50];
printf("Pick a vegetable to go in the salat: ");
fflush(stdout); // same use case as above in the first input part of the code
while (getchar() != '\n') {} // clears the input buffer so it doesnt print out excess input from the fruit one
scanf(" %49[^\n]", vegetable); // the "[^\n]" means to read everything except a newline, which means you can input spaces inside now, 49 makes it so it doesnt crash once it has more than 50 characters
printf("The %s will be a perfect choice for this salat!", vegetable);
// END // END
return 0; return 0;