-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomRedirect.c
More file actions
53 lines (47 loc) · 1004 Bytes
/
customRedirect.c
File metadata and controls
53 lines (47 loc) · 1004 Bytes
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
#include "Header.h"
#include "customCd.h"
void customRedirect(char *in_text){
char str1[1000];
char str2[1000];
int counter = 0;
int pre_counter = 0;
int post_counter = 0;
int i=0;
while(in_text[i]!='|'){
str1[counter++] = in_text[i];
if( (in_text[i]!=' ') && (in_text[i]!='\t') ){
pre_counter++;
}
i++;
}
str1[counter] = '\0';
counter = 0;
i++;
while(in_text[i]!='\0'){
str2[counter++] = in_text[i];
if( (in_text[i]!=' ') && (in_text[i]!='\t') ){
post_counter++;
}
i++;
}
str2[counter] = '\0';
// return error if there is no command before/after the |
if(pre_counter==0){
printf("piping: Enter a Command before the '|'\n");
return;
}
if(post_counter==0){
printf("piping: Enter a Command after the '|'\n");
return;
}
// remove initial spaces from str2
while((str2[0]==' ') || (str2[0]=='\t')){
for(int j=1;j<strlen(str2);j++){
str2[j-1] = str2[j];
}
str2[strlen(str2)-1] = '\0';
}
printf("%s\n", str1);
printf("%s\n", str2);
return;
}