Question: Language is in C. Need help troubleshooting my code Goal of code: * Replace strings with a new string. * Append an s to the

Language is in C. Need help troubleshooting my code

Goal of code:

* Replace strings with a new string.

* Append an s to the end of your input string if it's not a keyword.

* Insert a period at the end, if you have an empty input string do not insert a period

Problems:

//Why does my code stop at only 2 input strings

//If I insert a character my empty string case works but it's still bugged where no string is printed at all besides the period.

//Edge case for consecutive key words? Doing str1 str1 results in just "is str1 is str1s"

I've rewritten the input strings in case of academic integrity issues.

int main(int argc, char** argv) {

int counter = 0;

for(int i = 0; i

counter = i;

if(strcmp(argv[i],"str1")==0){

printf("%s", "is str1 ");

if(strcmp(argv[i+1],"str2")==0){

printf("%s ", "is str2");

}

else if(strcmp(argv[i+1],"str3")==0){

printf("%s ", "is str3");

}

else if(strcmp(argv[i+1],"str 4")==0){

printf("%s ", "is str4");

}

else{

printf("%s ",strncat(argv[i+1],"s",1));

}

}

if (*argv[0] != '\0'){

printf("%s ", ".");

}

*/

printf("%d ",counter);

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!