Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
master-embedded-systems
c-exercise-solutions public
Commits
c8da898f
Commit
c8da898f
authored
Jan 09, 2018
by
Dominik Widhalm
Browse files
Fixed several relicts from former example solutions
Again, thanks to Ralf Ziefuhs for pointing that out too
parent
cd63e9d5
Changes
15
Hide whitespace changes
Inline
Side-by-side
ch_3/task_09/main.c
View file @
c8da898f
...
...
@@ -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: "
);
...
...
ch_3/task_10/main.c
View file @
c8da898f
...
...
@@ -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: "
);
...
...
ch_3/task_13/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
ch_3/task_15/main.c
View file @
c8da898f
...
...
@@ -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
))
{
...
...
ch_4/task_09/main.c
View file @
c8da898f
...
...
@@ -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
"
);
...
...
ch_4/task_14/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
ch_6/task_02/main.c
View file @
c8da898f
...
...
@@ -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
"
);
}
...
...
ch_6/task_04/main.c
View file @
c8da898f
...
...
@@ -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: "
);
...
...
ch_6/task_05/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
ch_6/task_06/main.c
View file @
c8da898f
...
...
@@ -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 str
in
g
*/
path
[
strlen
(
path
)
-
1
]
=
'\0'
;
/*
Remove trailing newl
in
e
*/
strtok
(
path
,
"
\n
"
)
;
/* Scan directory and read in the songs */
if
(
songs_scan
(
&
head
,
path
)
==
0
)
{
...
...
ch_6/task_07/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
ch_6/task_08/main.c
View file @
c8da898f
...
...
@@ -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
);
...
...
ch_6/task_09/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
ch_6/task_10/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
ch_6/task_11/main.c
View file @
c8da898f
...
...
@@ -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 */
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment