Commit b286d722 authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

Merge branch 'master' of gitlab.mff.cuni.cz:teaching/nswi098/cecko/skeleton into skeleton_master

parents fcf2d07f dec659cf
......@@ -70,6 +70,13 @@ MAKE_TEST("4" "testexpr-ptrop")
MAKE_TEST("4" "testexpr-sizeof")
MAKE_TEST("4" "testexpr-struct")
MAKE_TEST("5" "test1")
MAKE_TEST("5" "test2typedef")
MAKE_TEST("5" "testcontrol-bool")
MAKE_TEST("5" "testcontrol-for")
MAKE_TEST("5" "testcontrol-if")
MAKE_TEST("5" "testcontrol-ptrrelop")
MAKE_TEST("5" "testcontrol-relop")
MAKE_TEST("5" "testcontrol-shortcut")
MAKE_TEST("5" "testcontrol-while")
MAKE_TEST("5" "testall-fib")
MAKE_TEST("5" "testall-ptrop")
MAKE_TEST("5" "testall-stack")
// fibbonacci
int fib(int x)
{
int s;
if (x <= 2)
return 1;
else
{
s = fib(x - 1) + fib(x - 2);
return s;
}
}
void fibtest(void)
{
int n;
int s;
printf("... fibtest ...\n");
n = 20;
s = fib(n);
printf("fib(%d) returned %d\n", n, s);
}
int main(int argc, char** argv)
{
fibtest();
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
typedef struct _file_s_0 FILE_0;
// --- FUNCTION DECLARATIONS ---
int fib_3(int);
void fibtest_15();
int main_25(int,char**);
void*memset_0(void*,int,int);
int printf_0(const char*,...);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
// --- FUNCTION DEFINITIONS ---
int fib_3(int x_3){
int s_5;
{
}
}
void fibtest_15(void){
int n_17;
int s_18;
}
int main_25(int argc_25,char**argv_25){
}
========== starting main() ==========
... fibtest ...
fib(20) returned 6765
========== main() returned 0 ==========
========== cecko5 done ==========
// pointer arithmetics
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)
{
int locvar;
locvar = ch + 1;
*p = ch;
ch = locvar;
p = p + 1;
}
*p = 0;
printf("%s\n", arr);
}
int main(int argc, char** argv)
{
pointerarithmeticstest();
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
typedef struct _file_s_0 FILE_0;
// --- FUNCTION DECLARATIONS ---
int main_26(int,char**);
void*memset_0(void*,int,int);
void pointerarithmeticstest_3();
int printf_0(const char*,...);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
// --- FUNCTION DEFINITIONS ---
int main_26(int argc_26,char**argv_26){
}
void pointerarithmeticstest_3(void){
char arr_5[27];
char ch_8;
char*e_7;
char*p_6;
{
int locvar_15;
}
}
========== starting main() ==========
... pointerarithmeticstest ...
ABCDEFGHIJKLMNOPQRSTUVWXYZ
========== main() returned 0 ==========
========== cecko5 done ==========
// linked-list stack
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;
}
void argreverttest(int argc, const char* const* 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);
}
}
int main(int argc, char** argv)
{
const char* n_argv[5];
n_argv[0] = "Zero";
n_argv[1] = "One";
n_argv[2] = "Two";
n_argv[3] = "Three";
n_argv[4] = "Four";
argreverttest(5, n_argv);
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
struct Str_5{
const char*key_6;
struct Str_5*next_7;
};
typedef struct _file_s_0 FILE_0;
typedef struct Str_5*str_ptr_3;
// --- FUNCTION DECLARATIONS ---
void argreverttest_48(int,const char*const*);
_Bool empty_32(struct Str_5**);
const char*front_37(struct Str_5**);
struct Str_5*get_str_15();
int main_71(int,char**);
void*memset_0(void*,int,int);
void pop_front_42(struct Str_5**);
int printf_0(const char*,...);
void push_front_23(struct Str_5**,const char*);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
struct Str_5 array_12[1000];
int array_end_13;
struct Str_5*root_10;
// --- FUNCTION DEFINITIONS ---
void argreverttest_48(int argc_48,const char*const*argv_48){
int i_51;
const char*z_50;
{
}
{
}
}
_Bool empty_32(struct Str_5**rootp_32){
}
const char*front_37(struct Str_5**rootp_37){
}
struct Str_5*get_str_15(void){
struct Str_5*p_17;
}
int main_71(int argc_71,char**argv_71){
const char*n_argv_73[5];
}
void pop_front_42(struct Str_5**rootp_42){
}
void push_front_23(struct Str_5**rootp_23,const char*key_23){
struct Str_5*p_25;
}
========== starting main() ==========
... argreverttest ...
sizeof(struct Str) = 16
argv[0] is "Zero"
argv[1] is "One"
argv[2] is "Two"
argv[3] is "Three"
argv[4] is "Four"
popped "Four"
popped "Three"
popped "Two"
popped "One"
popped "Zero"
========== main() returned 0 ==========
========== cecko5 done ==========
// implicit conversion to _Bool
int btoi(_Bool p)
{
return p;
}
_Bool itob(int p)
{
return p;
}
char* px;
int main(int argc, char** argv)
{
{
int i;
char x;
_Bool a, b, c, d, e, f, g, h;
i = 729;
a = i;
i = 0;
b = i;
x = 'X';
c = x;
x = 0;
d = x;
e = px;
px = &x;
f = px;
g = itob(-1);
h = !g;
printf("a=%d b=%d c=%d d=%d e=%d f=%d g=%d h=%d\n", btoi(a), btoi(b), btoi(c), btoi(d), btoi(e), btoi(f), btoi(g), btoi(h));
}
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
typedef struct _file_s_0 FILE_0;
// --- FUNCTION DECLARATIONS ---
int btoi_3(_Bool);
_Bool itob_8(int);
int main_15(int,char**);
void*memset_0(void*,int,int);
int printf_0(const char*,...);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
char*px_13;
// --- FUNCTION DEFINITIONS ---
int btoi_3(_Bool p_3){
}
_Bool itob_8(int p_8){
}
int main_15(int argc_15,char**argv_15){
{
_Bool a_20;
_Bool b_20;
_Bool c_20;
_Bool d_20;
_Bool e_20;
_Bool f_20;
_Bool g_20;
_Bool h_20;
int i_18;
char x_19;
}
}
========== starting main() ==========
a=1 b=0 c=1 d=0 e=0 f=1 g=1 h=0
========== main() returned 0 ==========
========== cecko5 done ==========
// if statement
void f(_Bool a, _Bool b, _Bool c)
{
_Bool d;
for (d = 0; a; c = d)
{
a = b;
b = c;
printf("looping ");
}
printf("done\n");
}
int main(int argc, char** argv)
{
f(0, 0, 0);
f(0, 0, 1);
f(0, 1, 0);
f(0, 1, 1);
f(1, 0, 0);
f(1, 0, 1);
f(1, 1, 0);
f(1, 1, 1);
int i;
for (i = 0; i < 10; i = i + 1)
{
printf("%d ", i);
}
printf("done\n");
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
typedef struct _file_s_0 FILE_0;
// --- FUNCTION DECLARATIONS ---
void f_3(_Bool,_Bool,_Bool);
int main_15(int,char**);
void*memset_0(void*,int,int);
int printf_0(const char*,...);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
// --- FUNCTION DEFINITIONS ---
void f_3(_Bool a_3,_Bool b_3,_Bool c_3){
_Bool d_5;
{
}
}
int main_15(int argc_15,char**argv_15){
int i_25;
{
}
}
========== starting main() ==========
done
done
done
done
looping done
looping done
looping looping done
looping looping looping done
0 1 2 3 4 5 6 7 8 9 done
========== main() returned 0 ==========
========== cecko5 done ==========
// if statement
void f(_Bool a, _Bool b, _Bool c)
{
if (a)
{
printf("a is true ");
}
if (b)
{
printf("b is true ");
if (c)
{
printf("c is also true ");
}
}
else
{
printf("b is false ");
if (c)
{
printf("c is true ");
}
else
{
printf("c is also false ");
}
}
printf("\n");
}
int main(int argc, char** argv)
{
f(0, 0, 0);
f(0, 0, 1);
f(0, 1, 0);
f(0, 1, 1);
f(1, 0, 0);
f(1, 0, 1);
f(1, 1, 0);
f(1, 1, 1);
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
typedef struct _file_s_0 FILE_0;
// --- FUNCTION DECLARATIONS ---
void f_3(_Bool,_Bool,_Bool);
int main_34(int,char**);
void*memset_0(void*,int,int);
int printf_0(const char*,...);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
// --- FUNCTION DEFINITIONS ---
void f_3(_Bool a_3,_Bool b_3,_Bool c_3){
{
}
{
{
}
}
{
{
}
{
}
}
}
int main_34(int argc_34,char**argv_34){
}
========== starting main() ==========
b is false c is also false
b is false c is true
b is true
b is true c is also true
a is true b is false c is also false
a is true b is false c is true
a is true b is true
a is true b is true c is also true
========== main() returned 0 ==========
========== cecko5 done ==========
// implicit conversion to _Bool
int btoi(_Bool p)
{
return p;
}
int* pi;
int main(int argc, char** argv)
{
{
int i;
const char * px, * py, * pz;
_Bool a, b, c, d, e, f;
int g;
px = "ABCDEFGHIJK";
py = px + 3;
pz = px + 7;
a = py < pz;
b = pz <= py;
c = px >= px;
d = py > pz;
e = pi != &i;
pi = &i;
f = pi == &i;
g = py - pz;
printf("a=%d b=%d c=%d d=%d e=%d f=%d g=%d\n", btoi(a), btoi(b), btoi(c), btoi(d), btoi(e), btoi(f), g);
}
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---
typedef struct _file_s_0 FILE_0;
// --- FUNCTION DECLARATIONS ---
int btoi_3(_Bool);
int main_10(int,char**);
void*memset_0(void*,int,int);
int printf_0(const char*,...);
int scanf_0(const char*,...);
int sprintf_0(char*,const char*,...);
int sscanf_0(const char*,const char*,...);
// --- GLOBAL VARIABLES ---
int*pi_8;
// --- FUNCTION DEFINITIONS ---
int btoi_3(_Bool p_3){
}
int main_10(int argc_10,char**argv_10){
{
_Bool a_15;
_Bool b_15;
_Bool c_15;
_Bool d_15;
_Bool e_15;
_Bool f_15;
int g_16;
int i_13;
const char*px_14;
const char*py_14;
const char*pz_14;
}
}
========== starting main() ==========
a=1 b=0 c=1 d=0 e=1 f=1 g=-4
========== main() returned 0 ==========
========== cecko5 done ==========
// implicit conversion to _Bool
int btoi(_Bool p)
{
return p;
}
int main(int argc, char** argv)
{
{
int i;
char x;
_Bool a, b, c, d, e, f;
i = 729;
a = i < 1000;
i = 0;
b = 1000 <= i;
x = 'X';
c = x >= 'X';
x = 0;
d = 'X' > x;
e = i != 0;
f = x == x;
printf("a=%d b=%d c=%d d=%d e=%d f=%d\n", btoi(a), btoi(b), btoi(c), btoi(d), btoi(e), btoi(f));
}
return 0;
}
========== tables ==========
// --- GLOBAL TYPEDEFS ---