I'm new to C and doing the implementation of shell. Now I'm struggling with the following question
There is a 2D char array. argv[0] contains "ls -l < test".
Then I want to use < to be the delimiter. When it's divided, I want to store the first part("ls -l") and second part("test") into two different new char array.
In my code, this is the implementation of IO redirection. I can only provide the part of the code as this is an assignment.
This is what I have so far.
while (argv[num_cmds]!=NULL )
{ // go though the current char array, check if there is a '<'
for(int i=0;i<strlen(argv[num_cmds]);i++){
if(argv[num_cmds][i]=='<'){
//first half
strcpy(cmds[num_cmds],strtok(argv[num_cmds], in));
//second half, not yet implemented
}
}
Now cmd[0] contains the first half. But I still need to deal with the second half. If my code structure is not doable, I'm happy to know the better method
Apologise in advance for my English