-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcow.c
54 lines (44 loc) · 1.38 KB
/
cow.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* \file cow.c
* \version 0.1 alpha
* \author Vernhes Yohann (lostsh)
* \date 20 Oct 2021
*/
#include <stdlib.h>
#include <stdio.h>
typedef unsigned short int wlen_t;
wlen_t length(const char*);
void showCow(int);
void showMessage(int, char**);
int main(int argc, char **argv){
if(argc == 1){
printf("Usage: %s [message]\n", argv[0]);
return 1;
}
showMessage(argc, argv);
showCow(4);
return 0;
}
void showMessage(int argc, char **argv){
int msg_len = argc-2;//count spaces between arguments except first arg and first space
for(int i=1;i<argc;i++) msg_len+=length(*(argv+i));
printf(" ");
for(int i=0;i<msg_len+2;i++) printf("_");
printf("\n<");
for(int i=1;i<argc;i++) printf(" %s", *(argv+i));
printf(" >\n ");
for(int i=0;i<msg_len+2;i++) printf("-");
printf("\n");
}
void showCow(int shift_size){
char shift[shift_size];
for(int i=0;i<shift_size;i++) *(shift+i) = ' ';
*(shift+shift_size-1) = '\0';
//printf("%s\\ ^__^\n%s \\ (oo)\\_______\n%s (__) \\ )\\/\\\n%s ||----w |\n%s || ||\n", shift, shift, shift, shift, shift);
printf("%s^__^\n%s(oo)\\_______\n%s(__) \\ )\\/\\\n%s ||----w |\n%s || ||\n", shift, shift, shift, shift, shift);
}
wlen_t length(const char *txt){
wlen_t size = 0;
while('\0' != *(txt+size)) size++;
return size;
}