diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-28 21:16:58 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-28 21:21:44 +0700 |
commit | 0887d8f96950a060a122e14ed2981182ff1eb37d (patch) | |
tree | 68be7a59c323c1fd901455ffae8f21874c4bb4c6 /usth/ICT2.1/labwork/3/Ex1.c | |
parent | e461df7573c2b7b7e26c965d8cf2d8e175d67378 (diff) | |
download | cp-0887d8f96950a060a122e14ed2981182ff1eb37d.tar.gz |
[usth/ICT2.1] Algorithm and Data Structures
Diffstat (limited to 'usth/ICT2.1/labwork/3/Ex1.c')
-rw-r--r-- | usth/ICT2.1/labwork/3/Ex1.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/usth/ICT2.1/labwork/3/Ex1.c b/usth/ICT2.1/labwork/3/Ex1.c new file mode 100644 index 0000000..90b3ca5 --- /dev/null +++ b/usth/ICT2.1/labwork/3/Ex1.c @@ -0,0 +1,38 @@ +/* + * Reverse name from stdin. + * This is free and unencumbered software released into the public domain. + */ + +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> + +#include "stack.h" + +int main() +{ + stack *s = mkstack(); + char c, *p; + + while ((c = getchar()) != EOF) { + p = malloc(sizeof(char *)); + *p = isspace(c) ? 32 : c; + stack_push(s, p); + } + + while (!stack_empty(s) && *(char *) stack_top(s) == 32) { + p = stack_pop(s); + free(p); + } + + c = 32; + while (!stack_empty(s)) { + p = stack_pop(s); + putchar(c == 32 ? toupper(c = *p) : tolower(c = *p)); + free(p); + } + + putchar(10); + + return 0; +} |