-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.c
More file actions
75 lines (58 loc) · 1.38 KB
/
echo.c
File metadata and controls
75 lines (58 loc) · 1.38 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
// #include "prompt.h"
#include "headers.h"
// #include "inputgiven.h"
// #include "echo1.h"
void echo(int rdhere, int wrthere , char *inp)
{
// printf("hehe\n");
// printf("inpobt %s\n",inp);
// printf("IN echo %d %d %d\n",STDIN_FILENO,STDOUT_FILENO,wrthere);
int realin,realout,red;
realin=dup(STDIN_FILENO);
realout=dup(STDOUT_FILENO);
if(rdhere!=STDIN_FILENO)
{
// printf("asdadsasd\n");
dup2(rdhere,STDIN_FILENO);
}
if(wrthere!=STDOUT_FILENO)
{
// printf("herealreat");
dup2(wrthere,STDOUT_FILENO);
}
char* token1 = strtok(inp, " ");
token1 = strtok(NULL, " ");
while (token1 != NULL)
{
// fprintf(wrthere,"%s ", token1);
write(wrthere,token1,strlen(token1));
write(wrthere," ",1);
token1 = strtok(NULL, " ");
}
// write(wrthere ,"\n", sizeof("\n"));
// int var=0;
// while(inp[var] != '"')
// {
// var++;
// }
// // printf("%ld",strlen(inp));
// // var++;
// for(int i = var;i<strlen(inp);i++)
// {
// // printf("hehe\n");
// if(inp[i] != '"'){
// printf("%c",inp[i]);
// }
// }
if(rdhere!=STDIN_FILENO)
{
dup2(realin,STDIN_FILENO);
}
if(wrthere!=STDOUT_FILENO)
{
dup2(realout,STDOUT_FILENO);
}
red=close(realin);
red=close(realout);
printf("\n"); //fix this
}