Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dsprog
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Manuel Bucher
dsprog
Commits
213cfafe
Commit
213cfafe
authored
6 years ago
by
Manuel Bucher
Browse files
Options
Downloads
Patches
Plain Diff
added more warnings
parent
558632c7
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile
+1
-1
1 addition, 1 deletion
Makefile
loesung.c
+25
-25
25 additions, 25 deletions
loesung.c
with
26 additions
and
26 deletions
Makefile
+
1
−
1
View file @
213cfafe
all
:
loesung
WARNINGS
=
-Wall
-Werror
OPTIONAL
=
-We
rror
-Wpedantic
OPTIONAL
=
-We
xtra
-Wpedantic
-Wshadow
DEBUG
=
-ggdb
-fno-omit-frame-pointer
OPTIMIZE
=
-O3
-std
=
c11
...
...
This diff is collapsed.
Click to expand it.
loesung.c
+
25
−
25
View file @
213cfafe
...
...
@@ -21,7 +21,7 @@ typedef struct List {
/** Initialisieren einer leeren Liste */
void
list_init
(
List
*
s
)
{
s
->
p_top
=
0
;
s
->
p_top
=
NULL
;
s
->
size
=
0
;
}
...
...
@@ -35,10 +35,10 @@ Tile* list_push(List *s) {
p_tile
->
x
=
0
;
p_tile
->
y
=
0
;
p_tile
->
p_next
=
s
->
p_top
;
p_tile
->
p_prev
=
0
;
p_tile
->
p_prev
=
NULL
;
s
->
p_top
=
p_tile
;
s
->
size
++
;
if
(
p_tile
->
p_next
!=
0
)
{
if
(
p_tile
->
p_next
!=
NULL
)
{
p_tile
->
p_next
->
p_prev
=
p_tile
;
}
return
p_tile
;
...
...
@@ -51,7 +51,7 @@ Tile* list_push(List *s) {
Tile
*
list_pop
(
List
*
s
)
{
Tile
*
p_tile
=
s
->
p_top
;
s
->
p_top
->
p_next
=
p_tile
->
p_next
;
s
->
p_top
->
p_prev
=
0
;
s
->
p_top
->
p_prev
=
NULL
;
return
p_tile
;
}
...
...
@@ -61,8 +61,8 @@ Tile* list_pop(List *s) {
*/
void
list_free
(
List
*
s
)
{
Tile
*
p_cur
=
s
->
p_top
;
s
->
p_top
=
0
;
while
(
p_cur
!=
0
)
{
s
->
p_top
=
NULL
;
while
(
p_cur
!=
NULL
)
{
Tile
*
p_next
=
p_cur
->
p_next
;
free
(
p_cur
);
p_cur
=
p_next
;
...
...
@@ -81,7 +81,8 @@ typedef enum ReadResult {
typedef
struct
Field
{
Tile
t_min
;
Tile
t_max
;
List
tiles
;
List
tile_list
;
Tile
tile_array
[];
}
Field
;
/** Parsen einer Kachel(Tile) aus einer Zeile von StdIn
...
...
@@ -155,13 +156,13 @@ inline uint32_t max(uint32_t a, uint32_t b) {
* Parameter:
* - Field* f pointer auf ein uninitialisiertes Feld, nach dem ausfuehren der
* Funktion ist das Feld initialisiert, wenn es sich um eine gueltige Eingabe
* handelt. `f->
num_tiles
` Ist im Fehlerfall die Zeile, in dem die Eingabe
* handelt. `f->
tile_list->size
` Ist im Fehlerfall die Zeile, in dem die Eingabe
* ungueltig ist.
*
* Return:
* - ReadResult:
* ReadOk, falls das lesen
e
rfolgreich war
* ReadErr..., falls die
e
ingabe ungueltig ist.
f
ist dann nicht vollstaendig
* ReadOk, falls das lesen
E
rfolgreich war
* ReadErr..., falls die
E
ingabe ungueltig ist.
`f`
ist dann nicht vollstaendig
* initialisiert
*/
ReadResult
parse_input
(
Field
*
f
)
{
...
...
@@ -170,10 +171,10 @@ ReadResult parse_input(Field *f) {
f
->
t_max
.
x
=
0
;
f
->
t_max
.
y
=
0
;
// initialisieren der Liste
list_init
(
&
f
->
tile
s
);
list_init
(
&
f
->
tile
_list
);
while
(
1
)
{
Tile
*
t
=
list_push
(
&
f
->
tile
s
);
// neues Element in die Liste einfuegen
Tile
*
t
=
list_push
(
&
f
->
tile
_list
);
// neues Element in die Liste einfuegen
ReadResult
result
=
read_line
(
t
);
switch
(
result
)
{
case
ReadOk
:
...
...
@@ -184,8 +185,8 @@ ReadResult parse_input(Field *f) {
f
->
t_max
.
y
=
max
(
f
->
t_max
.
x
,
t
->
y
);
break
;
case
ReadEof
:
list_pop
(
&
f
->
tile
s
);
if
(
f
->
tile
s
.
size
==
1
)
{
list_pop
(
&
f
->
tile
_list
);
if
(
f
->
tile
_list
.
size
==
1
)
{
return
ReadEof
;
}
else
{
return
ReadOk
;
...
...
@@ -196,15 +197,14 @@ ReadResult parse_input(Field *f) {
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
void
)
{
Field
f
;
ReadResult
result
=
parse_input
(
&
f
);
switch
(
result
)
{
case
ReadOk
:
printf
(
"Valider Input
\n
"
);
printf
(
"Anzahl: %d
\n
"
,
f
.
tile
s
.
size
);
printf
(
"Anzahl: %d
\n
"
,
f
.
tile
_list
.
size
);
printf
(
"Range(%d, %d), (%d, %d)
\n
"
,
f
.
t_min
.
x
,
f
.
t_min
.
y
,
f
.
t_max
.
x
,
f
.
t_max
.
y
);
...
...
@@ -216,22 +216,22 @@ int main (int argc,
// bei leerer Eingabe nichts ausgeben
return
EXIT_SUCCESS
;
case
ReadErrIntegerOverflow
:
fprintf
(
stderr
,
"Error in line %d: too big integer
\n
"
,
f
.
tile
s
.
size
);
list_free
(
&
f
.
tile
s
);
fprintf
(
stderr
,
"Error in line %d: too big integer
\n
"
,
f
.
tile
_list
.
size
);
list_free
(
&
f
.
tile
_list
);
return
EXIT_FAILURE
;
case
ReadErrNonDigitCharacter
:
fprintf
(
stderr
,
"Error in line %d: invalid character
\n
"
,
f
.
tile
s
.
size
);
list_free
(
&
f
.
tile
s
);
fprintf
(
stderr
,
"Error in line %d: invalid character
\n
"
,
f
.
tile
_list
.
size
);
list_free
(
&
f
.
tile
_list
);
return
EXIT_FAILURE
;
case
ReadErrTooFewNumbers
:
fprintf
(
stderr
,
"Error in line %d: Too few numbers, expected exactly 2
\n
"
,
f
.
tile
s
.
size
);
list_free
(
&
f
.
tile
s
);
f
.
tile
_list
.
size
);
list_free
(
&
f
.
tile
_list
);
return
EXIT_FAILURE
;
case
ReadErrTooManyNumbers
:
fprintf
(
stderr
,
"Error in line %d: Too much numbers, expected exactly 2
\n
"
,
f
.
tile
s
.
size
);
list_free
(
&
f
.
tile
s
);
f
.
tile
_list
.
size
);
list_free
(
&
f
.
tile
_list
);
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment