more tests
This commit is contained in:
parent
d0f8b3e0ad
commit
1bcff515b7
22 changed files with 191 additions and 58 deletions
7
test/io/echo.c
Normal file
7
test/io/echo.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
int getchar();
|
||||
int putchar(int ch);
|
||||
|
||||
int main() {
|
||||
for (char ch; (ch = getchar()) != -1; putchar(ch));
|
||||
putchar('\n');
|
||||
}
|
1
test/io/echo.in
Normal file
1
test/io/echo.in
Normal file
|
@ -0,0 +1 @@
|
|||
hello world
|
2
test/io/echo.out
Normal file
2
test/io/echo.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
hello world
|
||||
0
|
35
test/io/escape.c
Normal file
35
test/io/escape.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
int offset = 0;
|
||||
|
||||
int get() {
|
||||
return "hello\\n\\tworld\\\\\\'\\\"\\0\r\t\0"[offset++];
|
||||
}
|
||||
|
||||
int putchar(int ch);
|
||||
|
||||
int main() {
|
||||
char ch;
|
||||
while ((ch = get()) != 0) {
|
||||
if (ch == '\\') {
|
||||
ch = get();
|
||||
if (ch == 'n') {
|
||||
ch = '\n';
|
||||
} else if (ch == 't') {
|
||||
ch = '\t';
|
||||
} else if (ch == 'r') {
|
||||
ch = '\r';
|
||||
} else if (ch == '0') {
|
||||
break;
|
||||
} else if (ch == '\\') {
|
||||
ch = '\\';
|
||||
} else if (ch == '\'') {
|
||||
ch = '\'';
|
||||
} else if (ch == '\"') {
|
||||
ch = '\"';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar(ch);
|
||||
}
|
||||
return 0;
|
||||
}
|
2
test/io/escape.out
Normal file
2
test/io/escape.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
hello
|
||||
world\'"0
|
16
test/io/extern.c
Normal file
16
test/io/extern.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
int fprintf(void* stream, char* format, ...);
|
||||
int fscanf(void* stream, char* format, ...);
|
||||
int sprintf(char* str, char* format, ...);
|
||||
|
||||
extern void* stdin;
|
||||
extern void* stdout;
|
||||
|
||||
int main() {
|
||||
char buffer[4096];
|
||||
int a;
|
||||
int b;
|
||||
fscanf(stdin, "%d %d", &a, &b);
|
||||
sprintf(buffer, "The sum of %d and %d is %d\n", a, b, a + b);
|
||||
fprintf(stdout, buffer);
|
||||
return 0;
|
||||
}
|
1
test/io/extern.in
Normal file
1
test/io/extern.in
Normal file
|
@ -0,0 +1 @@
|
|||
3 4
|
2
test/io/extern.out
Normal file
2
test/io/extern.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
The sum of 3 and 4 is 7
|
||||
0
|
Loading…
Add table
Add a link
Reference in a new issue