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
teaching
nswi098
Cecko
skeleton
Commits
d59c45b2
Commit
d59c45b2
authored
Oct 23, 2020
by
Bednárek David RNDr. Ph.D.
Browse files
test2typedef.c
parent
af72fe68
Changes
2
Hide whitespace changes
Inline
Side-by-side
test/CMakeLists.txt
View file @
d59c45b2
...
...
@@ -27,6 +27,13 @@ MAKE_TEST("1" "testla-num-n")
MAKE_TEST
(
"1"
"testla-str-n"
)
MAKE_TEST
(
"2"
"test1"
)
MAKE_TEST
(
"2"
"test2typedef"
)
MAKE_TEST
(
"3"
"test1"
)
MAKE_TEST
(
"3"
"test2typedef"
)
MAKE_TEST
(
"4"
"test1"
)
MAKE_TEST
(
"4"
"test2typedef"
)
MAKE_TEST
(
"5"
"test1"
)
MAKE_TEST
(
"5"
"test2typedef"
)
test/test2typedef.c
0 → 100644
View file @
d59c45b2
// fibbonacci
FILE
*
myout
;
int
fib
(
int
p
);
typedef
struct
Str
*
str_ptr
;
struct
Str
{
const
char
*
key
;
str_ptr
next
;
};
str_ptr
root
;
struct
Str
array
[
1000
];
int
array_end
;
str_ptr
get_str
(
void
)
{
str_ptr
p
;
p
=
&
array
[
array_end
];
array_end
=
array_end
+
1
;
return
p
;
}
void
push_front
(
str_ptr
*
rootp
,
const
char
*
key
)
{
str_ptr
p
;
p
=
get_str
();
(
*
p
).
key
=
key
;
(
*
p
).
next
=
*
rootp
;
*
rootp
=
p
;
}
_Bool
empty
(
str_ptr
*
rootp
)
{
return
!*
rootp
;
}
const
char
*
front
(
str_ptr
*
rootp
)
{
return
(
**
rootp
).
key
;
}
void
pop_front
(
str_ptr
*
rootp
)
{
*
rootp
=
(
**
rootp
).
next
;
}
int
fib
(
int
x
)
{
int
s
;
if
(
x
<=
2
)
return
1
;
else
{
s
=
fib
(
x
-
1
)
+
fib
(
x
-
2
);
return
s
;
}
}
void
stringtest
(
void
)
{
char
arr
[
100
];
int
i
;
char
t
[
40
];
printf
(
"... stringtest ...
\n
"
);
sprintf
(
arr
,
"%d %s"
,
1
,
"text"
);
printf
(
"sprintf: %s
\n
"
,
arr
);
i
=
-
1
;
t
[
0
]
=
0
;
sscanf
(
arr
,
"%d%s"
,
&
i
,
t
);
printf
(
"sscanf: %d %s
\n
"
,
i
,
t
);
/*
printf("Enter a number\n");
scanf("%d", &i);
printf("The number was %d\n", i);
*/
memset
(
t
,
'X'
,
39
);
t
[
39
]
=
0
;
printf
(
"%s
\n
"
,
t
);
}
void
pointerarithmeticstest
(
void
)
{
char
arr
[
27
];
char
*
p
;
char
*
e
;
char
ch
;
printf
(
"... pointerarithmeticstest ...
\n
"
);
ch
=
'A'
;
p
=
arr
;
e
=
arr
+
26
;
while
(
p
!=
e
)
{
*
p
=
ch
;
ch
=
ch
+
1
;
p
=
p
+
1
;
}
*
p
=
0
;
printf
(
"%s
\n
"
,
arr
);
}
void
argreverttest
(
int
argc
,
char
**
argv
)
{
const
char
*
z
;
int
i
;
printf
(
"... argreverttest ...
\n
"
);
printf
(
"sizeof(struct Str) = %d
\n
"
,
sizeof
(
struct
Str
));
i
=
0
;
while
(
i
<
argc
)
{
z
=
argv
[
i
];
printf
(
"argv[%d] is
\"
%s
\"\n
"
,
i
,
z
);
push_front
(
&
root
,
z
);
i
=
i
+
1
;
}
while
(
!
empty
(
&
root
))
{
z
=
front
(
&
root
);
pop_front
(
&
root
);
printf
(
"popped
\"
%s
\"\n
"
,
z
);
}
}
void
fibtest
(
void
)
{
int
n
;
int
s
;
printf
(
"... fibtest ...
\n
"
);
n
=
20
;
s
=
fib
(
n
);
printf
(
"fib(%d) returned %d
\n
"
,
n
,
s
);
}
_Bool
status
;
_Bool
test
(
void
)
{
return
status
;
}
int
main
(
int
argc
,
char
**
argv
)
{
status
=
0
;
printf
(
"This is test1.c main()
\n
"
);
argreverttest
(
argc
,
argv
);
fibtest
();
stringtest
();
pointerarithmeticstest
();
if
(
test
())
{
printf
(
"Going to die
\n
"
);
printf
(
"DEATH=%s
\n
"
,
999999999
);
}
return
0
;
}
// /* this should not start multi-line comment
/*
/*
testing nesting
*/
*/
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