-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewcow.c
More file actions
98 lines (92 loc) · 2.69 KB
/
newcow.c
File metadata and controls
98 lines (92 loc) · 2.69 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* @Author: JIANG Yilun
* @Date: 2022-04-24 18:07:27
* @LastEditTime: 2022-04-26 17:57:15
* @LastEditors: JIANG Yilun
* @Description:
* @FilePath: /Projet_cowsay_L1S2/newcow.c
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int affiche_vache(int *length, char *message, char *eyes, char *tongue, int *tail, char *balls)
{
printf(" -");
for (int i = 0; i <= *length; i++)
{
printf("-");
}
printf("\n");
printf("< %s >\n", message);
printf(" -");
for (int i = 0; i <= *length; i++)
{
printf("-");
}
printf("\n");
printf(" \\ ^__^\n");
printf(" \\ (%s)\\_______\n", eyes);
printf(" (__)\\ )\\");
for (int i = 0; i < *tail; i++)
{
printf("/\\");
}
printf("\n");
printf(" %s ||----w |%s\n", tongue, balls);
printf(" || ||\n");
printf("\n");
return 0;
}
void update() { printf("\033[H\033[J"); }
void gotoxy(x, y) { printf("\033[%d;%dH", x, y); }
// TODO: hello
int main(int argc, char *argv[])
{
char *eyes = "oo"; // default eyes
char *tongue = " "; // default tongue
char *message = "--help to display help"; // default message
char *balls = " "; // default balls
int tail = 1; // default tail
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--eyes") == 0)
{
eyes = argv[i + 1];
}
if (strcmp(argv[i], "-T") == 0 || strcmp(argv[i], "--tongue") == 0)
{
tongue = argv[i + 1];
}
if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--message") == 0)
{
message = argv[i + 1];
}
if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--tail") == 0)
{
tail = atoi(argv[i + 1]);
}
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--balls") == 0)
{
balls = argv[i + 1];
}
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
printf("\n");
printf("Usage: newcow [OPTION]...\n");
printf("\n");
printf("Options:\n");
printf(" -e, --eyes=STRING eyes of the cow (default: oo)\n");
printf(" -t, --tongue=STRING tongue of the cow (default: )\n");
printf(" -m, --message=STRING message to display (default: none)\n");
printf(" -h, --help display this help and exit\n");
printf("\n");
return 0;
}
}
if (argc % 2 == 0)
{
message = argv[argc - 1];
}
int length = strlen(message);
affiche_vache(&length, message, eyes, tongue, &tail, balls);
}