-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.c
More file actions
42 lines (36 loc) · 1.01 KB
/
echo.c
File metadata and controls
42 lines (36 loc) · 1.01 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
#include "headers.h"
void echo(char *command, ll n) {
if(n==1){ /* echo */
return;
}
char* p;
char string[2000]="";
p = strstr(command, "echo ");
strcpy(string, p+strlen("echo "));
int len = strlen(string);
if(string[0]=='\"' && string[len-1]=='\"'){ /* echo "<text>" */
string[len-1]='\0';
printf("%s\n", &string[1]);
}
else if(string[0]=='\'' && string[len-1]=='\''){ /* echo '<text>' */
string[len-1]='\0';
printf("%s\n", &string[1]);
}
else{ /* echo <text> */
int i = 0;
while (i < len)
{
if(string[i]==' ' && (string[i+1]==' ' || string[i-1]==' '))
{
for(int j=i;j<len;j++)
string[j]=string[j+1];
len--;
}
else
{
i++;
}
}
printf("%s\n",string);
}
}