new input thing that works with spaces too
This commit is contained in:
parent
eb6781b969
commit
26ced52008
1 changed files with 8 additions and 0 deletions
8
main.c
8
main.c
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue