Compare commits
2 Commits
d404fc122e
...
181a0f3dcd
Author | SHA1 | Date | |
---|---|---|---|
![]() |
181a0f3dcd | ||
![]() |
7ec7448c36 |
@ -1,11 +1,14 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char * PROMPT = "ml' nob:";
|
||||
|
||||
const char * INPUT_OKAY = "Qapla'";
|
||||
|
||||
const char * OUT_OF_RANGE = "Qih mi'";
|
||||
const char * NOT_A_NUMBER = "Neh mi'";
|
||||
const char * INVALID_NUMBER = "bIjatlh 'e' yImev";
|
||||
|
||||
const char * QUOTES[9] = {
|
||||
"noH QapmeH wo' Qaw'lu'chugh yay chavbe'lu' 'ej wo' choqmeH may' DoHlu'chugh lujbe'lu'.",
|
||||
@ -20,18 +23,29 @@ const char * QUOTES[9] = {
|
||||
};
|
||||
|
||||
int main() {
|
||||
int input = 0;
|
||||
char *buf = NULL;
|
||||
size_t len = 0;
|
||||
char* end;
|
||||
|
||||
printf("%s\n", PROMPT);
|
||||
int result = scanf("%d", &input);
|
||||
|
||||
if(result != 1) {
|
||||
ssize_t chars_read = getline(&buf, &len, stdin);
|
||||
|
||||
errno = 0;
|
||||
long input = strtol(buf, &end, 10);
|
||||
|
||||
if(errno == ERANGE || chars_read == -1 || end == &buf[0]) {
|
||||
printf("%s\n", NOT_A_NUMBER);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(*end != '\n') {
|
||||
printf("%s\n", INVALID_NUMBER);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(input < 0 || input > 8) {
|
||||
printf("%s %d\n", OUT_OF_RANGE, input);
|
||||
printf("%s %ld\n", OUT_OF_RANGE, input);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
1
homework-00-warmup/test_data/0012_in.txt
Normal file
1
homework-00-warmup/test_data/0012_in.txt
Normal file
@ -0,0 +1 @@
|
||||
1.123
|
2
homework-00-warmup/test_data/0012_out.txt
Normal file
2
homework-00-warmup/test_data/0012_out.txt
Normal file
@ -0,0 +1,2 @@
|
||||
ml' nob:
|
||||
bIjatlh 'e' yImev
|
1
homework-00-warmup/test_data/0013_in.txt
Normal file
1
homework-00-warmup/test_data/0013_in.txt
Normal file
File diff suppressed because one or more lines are too long
2
homework-00-warmup/test_data/0013_out.txt
Normal file
2
homework-00-warmup/test_data/0013_out.txt
Normal file
@ -0,0 +1,2 @@
|
||||
ml' nob:
|
||||
bIjatlh 'e' yImev
|
1
homework-00-warmup/test_data/0014_in.txt
Normal file
1
homework-00-warmup/test_data/0014_in.txt
Normal file
@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002
|
3
homework-00-warmup/test_data/0014_out.txt
Normal file
3
homework-00-warmup/test_data/0014_out.txt
Normal file
@ -0,0 +1,3 @@
|
||||
ml' nob:
|
||||
Qapla'
|
||||
Qu' buSHa'chugh SuvwI', batlhHa' vangchugh, qoj matlhHa'chugh, pagh ghaH SuvwI''e'.
|
Loading…
x
Reference in New Issue
Block a user