Commit cd63e9d5 authored by Dominik Widhalm's avatar Dominik Widhalm
Browse files

Added %*c to scanf(" %c",..) to avoid leaving the \n in STDIN

Thanks to Ralf Ziefuhs for noticing this issue ;)
parent bc8ce8f4
......@@ -62,14 +62,14 @@ int main (void) {
/* Ask the user if another calculation should be done */
printf("Press any key to continue, end with [ESC]: ");
/* Read in the user input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
/* Check if the user wants to exit */
if (user_input == 27) {
/* Ask if the user really wants to quit */
printf("Do you really want to quit [Y/N]: ");
/* Read in the user input */
scanf(" %c",&confirmation);
scanf(" %c%*c",&confirmation);
/* For formatting reasons, print another newline */
printf("\n");
}
......
......@@ -59,7 +59,7 @@ int main (void) {
/* Ask the user to input an arithmetic operation */
printf("Please input the desired arithmetic operation (+,-,*,/): ");
/* Read in the user's input */
scanf(" %c",&operation);
scanf(" %c%*c",&operation);
/* Perform desired arithmetic operation */
switch (operation) {
......@@ -108,7 +108,7 @@ int main (void) {
/* Ask the user if another operation should be performed */
printf("Do you wish to perform another operation (Y/N): ");
/* Read in the user's input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
/* Repeat if user tells to */
} while(user_input == 'Y');
......
......@@ -63,7 +63,7 @@ int main (void) {
/* Ask if another round should be played */
printf("Do you want to play another round (Y/N): ");
/* Read in the user's input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
/* Print two newlines for formatting reasons */
printf("\n\n");
......
......@@ -32,7 +32,7 @@ int main (void) {
/* Inputs are required until the sequence was detected */
do {
/* Read in the user's input */
scanf(" %c",&input);
scanf(" %c%*c",&input);
/* Determine the "matching state" depending on the current state */
switch(state) {
case 0:
......
......@@ -72,7 +72,7 @@ int main (void) {
/* Ask the user if another calculation should be performed */
printf("Do you want to perform another tax calculation (Y/N): ");
/* Read in the user's input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
/* Print newlines for formatting reasons */
printf("\n\n");
} while (user_input != 'N');
......
......@@ -56,7 +56,7 @@ int main (void) {
/* Ask the user if another action should be taken */
printf("\nDo you want to change another account's balance (Y/N): ");
/* Read in the user's input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
} while (user_input=='Y');
/* Notify the user about the termination of the program */
......
......@@ -100,7 +100,7 @@ int main (void) {
/* Ask the user if another change is wanted */
printf("Do you want to perform another exchange (Y/N): ");
/* Read in the user's input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
} while (user_input == 'Y');
/* Notify the user about the termination of the program */
......
......@@ -81,7 +81,7 @@ int main (void) {
/* Ask the user to enter a character */
printf("\nYour guess: ");
/* Read in the user's input */
scanf(" %c",&input);
scanf(" %c%*c",&input);
/* Check if the user input was valid */
if ((input>='A') && (input<='Z')) {
......
......@@ -82,7 +82,7 @@ int main (void) {
/* Ask the user to enter a letter */
printf("\nPlease enter a letter: ");
/* Read in the user's input */
scanf(" %c",&input);
scanf(" %c%*c",&input);
/* Check if input is upper case letter */
if ((input>='A') && (input<='Z')) {
/* Convert letter to lower case */
......
......@@ -50,7 +50,7 @@ int main (void) {
/* Ask the user to enter the replacement character */
printf("Please enter the replacement character: ");
/* Read in the user's input */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
/* Exchange the character */
word[index-1] = user_input;
......@@ -62,7 +62,7 @@ int main (void) {
/* Ask if another exchange should be performed */
printf("\nDo you want to exchange another character (Y/N): ");
/* Read in the user's response */
scanf(" %c",&user_input);
scanf(" %c%*c",&user_input);
/* Repeat if user answered with 'Y'es */
} while (user_input == 'Y');
......
......@@ -123,7 +123,7 @@ int main (void) {
/* Ask the user to enter the desired arithmetic operation (+/-) */
printf("Should the numbers be added or subtracted (+/-): ");
/* Read in the user's input */
scanf(" %c",&operation);
scanf(" %c%*c",&operation);
/* Calculate the final number */
switch (operation) {
......
......@@ -191,7 +191,7 @@ int main (void) {
printf("(x) exit\n\n");
printf("Selection: ");
/* Read in the user's input */
scanf(" %c",&select);
scanf(" %c%*c",&select);
/* Do selected action */
switch (select) {
......@@ -199,7 +199,7 @@ int main (void) {
/* Ask the user in which form to enter the coordinates */
printf("\nDo you want to add (c)artesian or (p)olar coordinates: ");
/* Read in the user's input */
scanf(" %c",&type);
scanf(" %c%*c",&type);
switch (type) {
case 'c':
/* Ask user to enter the coordinates (Cartesian) */
......
......@@ -204,7 +204,7 @@ int main (void) {
/* Ask the user if he/she wants to add a person or quit */
printf("Do you want to add a person (y/n): ");
/* Read in the user's input */
scanf(" %c",&select);
scanf(" %c%*c",&select);
/* Check if the user wants to add a person */
if (select == 'y') {
......
......@@ -276,7 +276,7 @@ int main (void) {
printf("(x) exit\n");
printf("Input: ");
/* Read in the user's input */
scanf(" %c",&select);
scanf(" %c%*c",&select);
/* Do required action */
switch (select) {
......
......@@ -166,7 +166,7 @@ int main (void) {
printf("(x) exit\n");
printf("Input: ");
/* Read in the user's input */
scanf(" %c",&select);
scanf(" %c%*c",&select);
/* Do required action */
switch (select) {
......
......@@ -242,7 +242,7 @@ int main (void) {
printf("(x) exit\n");
printf("Input: ");
/* Read in the user's input */
scanf(" %c",&select);
scanf(" %c%*c",&select);
/* Do required action */
switch (select) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment