Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need some help writing this in C for a shell. Command Parsing (and print its com

ID: 664593 • Letter: N

Question

Need some help writing this in C for a shell.

Command Parsing (and print its components) using system(). Your shell should be able to parse the command from user

1. One command with arguments and options.

            For example, ls –la /home/xxx

                Command: la

                Options: -la

                Arguments: /home/xxx

2. Two commands with 1 pipe.

            For example, ls –la /home/xxx

                Command: la

                Options: -la

                Arguments: /home/xxx

            For example, ls | wc –l should be parsed and display

            Command: ls

            Pipe

            Command: wc –l

3. Two commands with semicolon. For example, ls ; date

4. One command with IO redirection symbol (<, >, >>)

            For example, ls < junk.txt > output.txt

            Command: ls

            File Redirection: <

            File: junk.txt

            File Redirection: >

File: output.txt

Explanation / Answer

#include<stdio.h>
#include<conio.h>
int main()
{
int arr[30];
int i,j,k,tmp,num;
printf("Enter total no. of elements : ");
scanf("%d", &num);
for(k=0; k<num; k++)
{
printf(" Enter %d number : ",k+1);
scanf("%d",&arr[k]);
}
for(i=num/2; i>0; i=i/2)
{
for(j=i; j<num; j++)
{
for(k=j-i; k>=0; k=k-i)
{
  if(arr[k+i]>=arr[k])
  break;
  else
{
tmp=arr[k];
arr[k]=arr[k+i];
arr[k+i]=tmp;
}
}
}
}
printf(" **** Shell Sorting **** ");
for(k=0; k<num; k++)
printf("%d ",arr[k]);
getch();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote