Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions

Question

1. Answer the question, What is human resource management?

Answered: 1 week ago

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago