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

Fixed several relicts from former example solutions

Again, thanks to Ralf Ziefuhs for pointing that out too
parent cd63e9d5
...@@ -20,7 +20,6 @@ int main (void) { ...@@ -20,7 +20,6 @@ int main (void) {
/*** Local Variables ***/ /*** Local Variables ***/
char input[80]; char input[80];
char output[80]; char output[80];
int ch;
int n; int n;
int i=0,j=0; int i=0,j=0;
...@@ -28,8 +27,6 @@ int main (void) { ...@@ -28,8 +27,6 @@ int main (void) {
printf("Please enter the key n: "); printf("Please enter the key n: ");
/* Read in the user's input */ /* Read in the user's input */
scanf("%d",&n); scanf("%d",&n);
/* Flush stdin buffer */
while (((ch = getchar()) != '\n') && (ch != EOF));
/* Ask the user to enter a string */ /* Ask the user to enter a string */
printf("Please enter a string: "); printf("Please enter a string: ");
......
...@@ -20,7 +20,6 @@ int main (void) { ...@@ -20,7 +20,6 @@ int main (void) {
/*** Local Variables ***/ /*** Local Variables ***/
char input[80]; char input[80];
char output[80]; char output[80];
int ch;
int n; int n;
int i=0; int i=0;
...@@ -28,8 +27,6 @@ int main (void) { ...@@ -28,8 +27,6 @@ int main (void) {
printf("Please enter the key n: "); printf("Please enter the key n: ");
/* Read in the user's input */ /* Read in the user's input */
scanf("%d",&n); scanf("%d",&n);
/* Flush stdin buffer */
while (((ch = getchar()) != '\n') && (ch != EOF));
/* Ask the user to enter a string */ /* Ask the user to enter a string */
printf("Please enter a Caesar decrypted string: "); printf("Please enter a Caesar decrypted string: ");
......
...@@ -34,6 +34,8 @@ int main (void) { ...@@ -34,6 +34,8 @@ int main (void) {
printf("Please enter the %d. name: ",(i+1)); printf("Please enter the %d. name: ",(i+1));
/* Read in the user's input */ /* Read in the user's input */
fgets(name[i],STRING_MAX,stdin); fgets(name[i],STRING_MAX,stdin);
/* Remove trailing newline */
strtok(name[i],"\n");
} }
/* Convert names to lower case */ /* Convert names to lower case */
......
...@@ -35,6 +35,8 @@ int main (void) { ...@@ -35,6 +35,8 @@ int main (void) {
printf("Please enter the first number as Roman numeral: "); printf("Please enter the first number as Roman numeral: ");
/* Read in the user's input */ /* Read in the user's input */
fgets(rom_value1,STRING_MAX,stdin); fgets(rom_value1,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(rom_value1,"\n");
/* Convert the first number to a decimal number */ /* Convert the first number to a decimal number */
while ((rom_value1[i]!='\0') && (i<40)) { while ((rom_value1[i]!='\0') && (i<40)) {
......
...@@ -129,8 +129,6 @@ int main (void) { ...@@ -129,8 +129,6 @@ int main (void) {
/*** Local Variables ***/ /*** Local Variables ***/
int students; int students;
int grades[STUDENT_MAX][NUM_LECTURES]; int grades[STUDENT_MAX][NUM_LECTURES];
/* Helper for buffer flushing */
int ch;
/* At least one user input is required */ /* At least one user input is required */
do { do {
...@@ -153,10 +151,9 @@ int main (void) { ...@@ -153,10 +151,9 @@ int main (void) {
for (int i=0; i<students; i++) { for (int i=0; i<students; i++) {
/* Temporary string for user input */ /* Temporary string for user input */
char string[STRING_MAX]; char string[STRING_MAX];
/* Flush stdin buffer */
while (((ch = getchar()) != '\n') && (ch != EOF));
/* Ask the user to enter the CSV string */ /* Ask the user to enter the CSV string */
printf("Please enter the %d grades in a CSV-like fashion: ",NUM_LECTURES); /* Read in the user's input */ printf("Please enter the %d grades in a CSV-like fashion: ",NUM_LECTURES);
/* Read in the user's input */
fgets(string,STRING_MAX,stdin); fgets(string,STRING_MAX,stdin);
/* Remove trailing newline */ /* Remove trailing newline */
strtok(string,"\n"); strtok(string,"\n");
......
...@@ -76,17 +76,13 @@ int main (void) { ...@@ -76,17 +76,13 @@ int main (void) {
/*** Local Variables ***/ /*** Local Variables ***/
char letter; char letter;
char string[STRING_MAX+1]; char string[STRING_MAX+1];
/* Helper for buffer flushing */
int ch;
int occurrence; int occurrence;
/* Ask the user to enter the desired letter */ /* Ask the user to enter the desired letter */
printf("Please enter the letter to be counted: "); printf("Please enter the letter to be counted: ");
/* Read in the user's input */ /* Read in the user's input */
scanf("%c",&letter); scanf(" %c%*c",&letter);
/* Flush stdin buffer */
while (((ch = getchar()) != '\n') && (ch != EOF));
/* Ask the user to input the string */ /* Ask the user to input the string */
printf("Please enter the string (max. %d letters):\n",STRING_MAX); printf("Please enter the string (max. %d letters):\n",STRING_MAX);
/* Read in the user's input */ /* Read in the user's input */
......
...@@ -118,8 +118,6 @@ int main (void) { ...@@ -118,8 +118,6 @@ int main (void) {
int temp; int temp;
feature abs; feature abs;
double price = 0.0; double price = 0.0;
/* Helper for buffer flushing */
int ch;
/* Read in 3 cars */ /* Read in 3 cars */
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
...@@ -165,8 +163,6 @@ int main (void) { ...@@ -165,8 +163,6 @@ int main (void) {
free(car); free(car);
} }
/* Flush stdin buffer */
while (((ch = getchar()) != '\n') && (ch != EOF));
/* Print a newline for formatting reasons */ /* Print a newline for formatting reasons */
printf("\n"); printf("\n");
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
/***** INCLUDES ***************************************************************/ /***** INCLUDES ***************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
/***** MACROS *****************************************************************/ /***** MACROS *****************************************************************/
...@@ -67,11 +68,15 @@ void list_add_person (person_t** head) { ...@@ -67,11 +68,15 @@ void list_add_person (person_t** head) {
printf("Please enter the person's first name: "); printf("Please enter the person's first name: ");
/* Read in the user's input */ /* Read in the user's input */
fgets(new->firstname,STRING_MAX,stdin); fgets(new->firstname,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(new->firstname,"\n");
/* Ask the user to input the persons last name */ /* Ask the user to input the persons last name */
printf("Please enter the person's last name: "); printf("Please enter the person's last name: ");
/* Read in the user's input */ /* Read in the user's input */
fgets(new->lastname,STRING_MAX,stdin); fgets(new->lastname,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(new->lastname,"\n");
/* Ask the user to input the persons year of birth */ /* Ask the user to input the persons year of birth */
printf("Please enter the person's year of birth: "); printf("Please enter the person's year of birth: ");
......
...@@ -263,8 +263,6 @@ int main (void) { ...@@ -263,8 +263,6 @@ int main (void) {
int day,month_tmp; int day,month_tmp;
month_t month; month_t month;
char select = 'x'; char select = 'x';
/* Helper for buffer flushing */
int ch;
/* Do as long as the users wants to do an action */ /* Do as long as the users wants to do an action */
do { do {
...@@ -284,9 +282,6 @@ int main (void) { ...@@ -284,9 +282,6 @@ int main (void) {
/** Add a new entry **/ /** Add a new entry **/
printf("\n... Adding a new entry ...\n"); printf("\n... Adding a new entry ...\n");
/* Flush stdin buffer */
while (((ch = getchar()) != '\n') && (ch != EOF));
/* Ask the user to enter the name of the event */ /* Ask the user to enter the name of the event */
printf("Please enter the name of the event (max. %d character): ",(STRING_MAX-1)); printf("Please enter the name of the event (max. %d character): ",(STRING_MAX-1));
/* Read in the user's input */ /* Read in the user's input */
......
...@@ -406,8 +406,8 @@ int main (void) { ...@@ -406,8 +406,8 @@ int main (void) {
printf("Please enter the name of the directory to scan: "); printf("Please enter the name of the directory to scan: ");
/* Read in the user input */ /* Read in the user input */
fgets(path,STRING_MAX,stdin); fgets(path,STRING_MAX,stdin);
/* Terminate the directory path string */ /* Remove trailing newline */
path[strlen(path)-1] = '\0'; strtok(path,"\n");
/* Scan directory and read in the songs */ /* Scan directory and read in the songs */
if (songs_scan(&head,path) == 0) { if (songs_scan(&head,path) == 0) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
/***** MACROS *****************************************************************/ /***** MACROS *****************************************************************/
...@@ -320,6 +321,8 @@ int main (void) { ...@@ -320,6 +321,8 @@ int main (void) {
printf("Please enter one of the numbers shown above: "); printf("Please enter one of the numbers shown above: ");
/* Read in the user's input as string */ /* Read in the user's input as string */
fgets(input,STRING_MAX,stdin); fgets(input,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(input,"\n");
/* Check if string contains a number */ /* Check if string contains a number */
if (sscanf(input,"%d",&number) == 0) { if (sscanf(input,"%d",&number) == 0) {
/* No number found */ /* No number found */
......
...@@ -426,6 +426,8 @@ int main (void) { ...@@ -426,6 +426,8 @@ int main (void) {
printf("Please enter the name of the text file: "); printf("Please enter the name of the text file: ");
/* Read in the user input */ /* Read in the user input */
fgets(path,STRING_MAX,stdin); fgets(path,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(path,"\n");
/* (Try to) read the given text file */ /* (Try to) read the given text file */
retval = list_read_textfile(&head,path); retval = list_read_textfile(&head,path);
......
...@@ -176,6 +176,8 @@ int main (void) { ...@@ -176,6 +176,8 @@ int main (void) {
printf("Please enter the desired command: "); printf("Please enter the desired command: ");
/* Read in the user's input */ /* Read in the user's input */
fgets(command,STRING_MAX,stdin); fgets(command,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(command,"\n");
/* (Try to) push the command on the stack */ /* (Try to) push the command on the stack */
ret = stack_push(&head,command); ret = stack_push(&head,command);
/* Check if pushing was successful */ /* Check if pushing was successful */
......
...@@ -252,6 +252,8 @@ int main (void) { ...@@ -252,6 +252,8 @@ int main (void) {
printf("Please enter the desired string: "); printf("Please enter the desired string: ");
/* Read in the user's input */ /* Read in the user's input */
fgets(string,STRING_MAX,stdin); fgets(string,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(string,"\n");
/* Ask the user to input the priority */ /* Ask the user to input the priority */
printf("Please enter the desired priority: "); printf("Please enter the desired priority: ");
/* Read in the user's input */ /* Read in the user's input */
......
...@@ -158,6 +158,8 @@ int main (void) { ...@@ -158,6 +158,8 @@ int main (void) {
printf(" ... please enter the %d. value: ",(i+1)); printf(" ... please enter the %d. value: ",(i+1));
/* Read in the user's input */ /* Read in the user's input */
fgets(temp,STRING_MAX,stdin); fgets(temp,STRING_MAX,stdin);
/* Remove trailing newline */
strtok(temp,"\n");
/* Analyze the given string */ /* Analyze the given string */
if (analyze_input(temp,curr) == VALID) { if (analyze_input(temp,curr) == VALID) {
/* Valid input */ /* Valid input */
......
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