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