Hello i want code where it will print out the following error messages when the
ID: 3750839 • Letter: H
Question
Hello i want code where it will print out the following error messages when the specfic argument case is passed through the code.
for N, the integer is in the first argument
ex. 1 all emptyfile
this would be one of the command line arguments being passed
You must detect the case where no arguments are passed. In that case, print the error message “NO
PHRASE LENGTH” and stop.
You must detect the case where the argument specified for N is not an integer. In that case, print the
error message “INVALID PHRASE LENGTH” and stop, also if the integer is negative
Print “NO MODE” if a second argument is missing
Print “INVALID MODE” if the second argument is something other than “all” or “top”
Explanation / Answer
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main( int argc, char *argv[] ) {
int num,len,i;
if( argc > 1 ) {
len = strlen(argv[1]);
for(i=0;i<len;i++)
{
if(isdigit(argv[1][i]) == 0){
printf("INVALID PHRASE LENGTH ");
return 1;
}
}
num = atoi(argv[1]);
if(num < 0){
printf("INVALID PHRASE LENGTH ");
return 1;
}
}
if(argc == 1 ) {
printf("NO PHRASE LENGTH ");
return 1;
}
if(argc == 3 ){
if( strcmp(argv[2],"all")!=0 && strcmp(argv[2],"top")!=0 )
{
printf("INVALID MODE ");
return 1;
}
}else{
printf("NO MODE ");
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.