added a third valgrind test for a third minigame
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
ddbd54b97c
commit
db87aaa8f0
12
.drone.yml
12
.drone.yml
@ -37,6 +37,18 @@ steps:
|
||||
- success
|
||||
- failure
|
||||
|
||||
- name: valgrind-test2
|
||||
pull: if-not-exists
|
||||
image: immawanderer/archlinux-cdev
|
||||
commands:
|
||||
- valgrind --log-file=valgrind_output ./pjc-0x02 < ./test_input2 > /dev/null
|
||||
- cat valgrind_output
|
||||
- grep "no leaks are possible" valgrind_output
|
||||
when:
|
||||
status:
|
||||
- success
|
||||
- failure
|
||||
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
|
111
main.c
111
main.c
@ -32,8 +32,10 @@ int get_userguess(){
|
||||
while( ok != 1){
|
||||
ok = scanf("%d", &x);
|
||||
if(ok == EOF){
|
||||
printf("[*] please, come on...\n");
|
||||
return 9000;
|
||||
printf("\ncaught Ctrl+D...\n");
|
||||
ok = 1;
|
||||
x = 2;
|
||||
break;
|
||||
}
|
||||
if(ok == 0){
|
||||
while (fgetc(stdin) != '\n'){
|
||||
@ -45,6 +47,24 @@ int get_userguess(){
|
||||
return x;
|
||||
}
|
||||
|
||||
void read_selection(int selection){
|
||||
int ok;
|
||||
while(ok != 1) {
|
||||
ok = scanf("%d", &selection);
|
||||
if(ok == EOF){
|
||||
printf("[*] please, come on...\n");
|
||||
ok = 1;
|
||||
lemmego();
|
||||
}
|
||||
if(ok == 0){
|
||||
while (fgetc(stdin) != '\n'){
|
||||
}
|
||||
lemmego();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void compare_guess_with_reality(int userguess, int reality){
|
||||
if(userguess == reality){
|
||||
printf("[*] you won because you've got luck. try me next time!\n");
|
||||
@ -74,7 +94,8 @@ void guess(){
|
||||
ok = scanf("%d", &userchoice);
|
||||
if(ok == EOF){
|
||||
printf("[*] please, come on...\n");
|
||||
return;
|
||||
lemmego();
|
||||
break;
|
||||
}
|
||||
if(ok == 0){
|
||||
while (fgetc(stdin) != '\n'){
|
||||
@ -128,23 +149,6 @@ void print_rand_bs(){
|
||||
}
|
||||
}
|
||||
|
||||
void read_selection(int selection){
|
||||
int ok;
|
||||
while(ok != 1) {
|
||||
ok = scanf("%d", &selection);
|
||||
if(ok == EOF){
|
||||
printf("[*] please, come on...\n");
|
||||
return;
|
||||
}
|
||||
if(ok == 0){
|
||||
while (fgetc(stdin) != '\n'){
|
||||
}
|
||||
lemmego();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void default_flow(char operator, int a, int b, int result){
|
||||
int answer = 0;
|
||||
@ -232,11 +236,78 @@ void another_bs(){
|
||||
}
|
||||
}
|
||||
|
||||
void print_some_multiples_of_five(){
|
||||
for (int i = 1; i <= 20; ++i) {
|
||||
printf("i = %d\n", i*5);
|
||||
}
|
||||
}
|
||||
|
||||
void gimme_leap_years(){
|
||||
int former, latter, selection;
|
||||
|
||||
printf("\ncalculate leap years for a given range\n");
|
||||
while ( selection != 2 ) {
|
||||
printf("\n1 - calculate\n"
|
||||
"2 - quit\n"
|
||||
">> ");
|
||||
selection = 0;
|
||||
selection = get_userguess();
|
||||
|
||||
switch (selection) {
|
||||
case 1:
|
||||
printf("the former year\n>> ");
|
||||
former = get_userguess();
|
||||
printf("the latter year\n>> ");
|
||||
|
||||
latter = get_userguess();
|
||||
if (former > latter) {
|
||||
int tmp = latter;
|
||||
latter = former;
|
||||
former = tmp;
|
||||
}
|
||||
|
||||
for (int i = former; i <= latter; ++i) {
|
||||
int year = i;
|
||||
if (year % 4 == 0) {
|
||||
if (year % 100 == 0) {
|
||||
if (year % 400 == 0) {
|
||||
printf("year %d is a leap year\n", year);
|
||||
continue;
|
||||
} else {
|
||||
printf("year %d is NOT a leap year\n", year);
|
||||
continue;
|
||||
}
|
||||
printf("year %d is NOT a leap year\n", year);
|
||||
continue;
|
||||
}
|
||||
printf("year %d is a leap year\n", year);
|
||||
continue;
|
||||
} else {
|
||||
printf("year %d is NOT a leap year\n", year);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
printf("range %d..%d (%d years)\n", former, latter, latter - former);
|
||||
break;
|
||||
case 2:
|
||||
lemmego();
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
printf("invalid option\n");
|
||||
selection = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
print_rand_bs();
|
||||
guess();
|
||||
another_bs();
|
||||
print_some_multiples_of_five();
|
||||
gimme_leap_years();
|
||||
return 0;
|
||||
}
|
||||
|
16
test_input2
Normal file
16
test_input2
Normal file
@ -0,0 +1,16 @@
|
||||
1
|
||||
2
|
||||
2020
|
||||
1
|
||||
500
|
||||
5
|
||||
1
|
||||
bs
|
||||
ok1
|
||||
1910
|
||||
1969
|
||||
1
|
||||
2005
|
||||
2505
|
||||
ktxbai
|
||||
2
|
Loading…
Reference in New Issue
Block a user