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

Hello. I have a C assignment. I have been too sick couple of days I was not able

ID: 3782344 • Letter: H

Question

Hello. I have a C assignment. I have been too sick couple of days I was not able to complete this. Can you possibly write this out. I am willing to give you a lot of credit if you could help me out. Thanks.

Your task is to implement a program that takes command-line arguments and checks whether each argument matches a particular pattern. The pattern to check is determined by a command-line flag -a, b, or -c, where the default mode is a. The patterns for each flag are described below. By default, your program should print "yes" for each matching argument and "no" for each non- matching argument, each on a separate line. If the t flag is provided, then your program should instead print nothing for non-matching arguments and it should print a converted value for each matching argument. Each pattern mode has an associated conversion, as described below At most one of a, b, or c will be provided. A -t flag can be provided before or after any of b, and -c. All flags (i.e,. up to two of them precede other command-line arguments. A non-flag argument never starts with All arguments are in ASCII

Explanation / Answer

#include<stdio.h>
#include<string.h>

//Function to check the pattern starts with -a.
int checka(char *argv)
{
int h=0,t=0,decimal=0;
int i=0;
while(argv[i]!='')
{
if(argv[i]=='h')
h++;
else if(argv[i]=='t')
t++;
else if(isdigit(argv[i]))
decimal++;

i++;
}
if(h%2==0 &&4<=t<=5 && 1<=decimal<=3)
return 1;

return 0;
}

//Function to check the pattern starts with -b.
int checkb(char *argv)
{
int k=0,n=0,decimal=0,upper=0;
int i=0;
while(argv[i]!='')
{

if(argv[i]=='n')
n++;
else if(argv[i]=='k')
k++;
else if(isdigit(argv[i]))
decimal++;
else if(isupper(argv[i]))
upper++;
i++;
}
if(k%2!=0 && upper%2!=0 && 1<=n<=2 && 1<=decimal<=3)
return 1;
return 0;
}

//Function to check the pattern starts with -c.
int checkc(char *argv)
{
int t=0,k=0,decimal=0,upper=0;
int i=0;
while(argv[i]!='')
{

if(argv[i]=='t')
t++;
else if(argv[i]=='k')
k++;
else if(isdigit(argv[i]))
decimal++;
else if(isupper(argv[i]))
upper++;

}
if(k>=0 && 1<=decimal<=3 && t>=3 && upper%2!=0)
return 1;
return 0;
}

//Function to convert the string in case pattern starts with -a or -t.
void converta(char *argv)
{
int i;
for(i=0;argv[i]!='';i++)
{
if(argv[i]=='G')
argv[i]='F';
else if(argv[i]=='F')
argv[i]='G';
}
printf(" ");
for(i=0;argv[i]!='';i++)
{
printf("%c",argv[i]);
}
}

//Function to convert the string in case pattern starts with -b or -t.
void convertb(char *argv)
{
char *b;
int i,j=0;
for(i=0;argv[i]!='';i++)
{
b[j]=argv[i];
b[j+1]=i%8;
j+=2;
}
printf(" ");
for(i=0;b[i]!='';i++)
{
printf("%c",b[i]);
}
}

//Function to convert the string in case pattern starts with -c or -t.
void convertc(char *argv)
{
char *b;
int i,k=0;
int flag=0;
for(i=0;argv[i]!='';i++)
{
if(flag==0 && argv[i]=='B')
{
flag=1;
}
else
{
b[k]=argv[i];
k++;
}
}
//For last B.
flag=0;
int h=k-1;
for(i=k-1;i>=0;i--)
{
if(flag==0 && b[i]=='B')
{
flag=1;
}
else
{
b[h]=b[i];
h--;
}
}
printf(" ");
for(i=0;b[i]!='';i++)
{
printf("%c",b[i]);
}
}

//argv[0] is the name of the program and rest all contains the command line arguments.
//argc is the number of arguments including name of the program.

int main(int argc, char *argv[])
{
int count;
if(argv[1]=="-a")
{
count=2;
while(count<=argc)
{
if(checka(argv[count]))
printf(" yes");
else
printf(" no");
count++;
}
}

else if(argv[1]=="-b")
{
count=2;
while(count<=argc)
{
if(checkb(argv[count]))
printf(" yes");
else
printf(" no");

count++;
}
}

else if(argv[1]=="-c")
{
count=2;
while(count<=argc)
{
if(checkc(argv[count]))
printf(" yes");
else
printf(" no");

count++;
}
}

else if((strcmp(argv[1],"-t")==0 && strcmp(argv[2],"-a")==0)|| (strcmp(argv[1],"-a")==0 && strcmp(argv[2],"-t")==0))
{
count=3;
while(count<=argc)
{
if(checka(argv[count]))
converta(argv[count]);
count++;
}
}

else if((strcmp(argv[1],"-t")==0 && strcmp(argv[2],"-b")==0 )|| (strcmp(argv[1],"-b")==0 && strcmp(argv[2],"-t")==0))
{
count=3;
while(count<=argc)
{
if(checkb(argv[count]))
convertb(argv[count]);
count++;
}
}

else if((strcmp(argv[1],"-t")==0 && strcmp(argv[2],"-c")==0 )|| (strcmp(argv[1],"-c")==0 && strcmp(argv[2],"-t")==0))
{
count=3;
while(count<=argc)
{
if(checkc(argv[count]))
convertc(argv[count]);
count++;
}
}

else
{
count=1;
while(count<=argc)
{
if(checka(argv[count]))
printf(" yes");
else
printf(" no");
count++;
}
}
}