-
Notifications
You must be signed in to change notification settings - Fork 2
/
echo.c
77 lines (65 loc) · 1.48 KB
/
echo.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "def.h"
void exEcho(char *cur)
{
cur = strtok(NULL, " \t");
while(cur != NULL)
{
int n = strlen(cur);
int doubleQuotes = 0;
int singleQuotes = 0;
for(int i=0; i<n; i++)
{
if(cur[i] == '"')
{
doubleQuotes++;
}
else if(cur[i] == '\'')
{
singleQuotes++;
}
}
for(int i = 0; i < n; i++)
{
if(singleQuotes%2 == 0 && doubleQuotes%2 == 0)
{
if(cur[i] == '"' || cur[i] == '\'')
{
continue;
}
else
{
printf("%c", cur[i]);
}
}
else if(singleQuotes%2 == 0)
{
if(cur[i] == '\'')
{
continue;
}
else
{
printf("%c", cur[i]);
}
}
else if(doubleQuotes%2 == 0)
{
if(cur[i] == '"')
{
continue;
}
else
{
printf("%c", cur[i]);
}
}
else
{
printf("%c", cur[i]);
}
}
printf(" ");
cur = strtok(NULL, " \t");
}
printf("\n");
}