-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathecho.c
More file actions
50 lines (46 loc) · 1.06 KB
/
echo.c
File metadata and controls
50 lines (46 loc) · 1.06 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
#include "headers.h"
void echo(char buff[][100], int k)
{
int i;
int lk = strlen(buff[(k - 1)]);
int flag = 0;
for (i = 1; i < k; i++)
{
int j;
int l = strlen(buff[i]);
for (j = 0; j < l; j++)
{
if (buff[i][j] == '\"' || buff[i][j] == '\'')
flag = 1;
}
}
if (buff[1][0] == '\"' && buff[(k - 1)][(lk - 1)] == '\"' || buff[1][0] == '\'' && buff[(k - 1)][(lk - 1)] == '\'')
flag = 0;
if (flag == 1)
{
printf("Invalid string\n");
return;
}
for (i = 1; i < k; i++)
{
if (buff[i][0] == '$')
{
char *e = getenv(buff[i] + 1);
if (e != NULL)
printf("%s ", e);
}
else
{
int j;
int l = strlen(buff[i]);
for (j = 0; j < l; j++)
{
if (buff[i][j] != '\"' || buff[i][j] != '\'')
printf ("%c", buff[i][j]);
}
printf (" ");
}
}
printf ("\n");
return;
}