Question: Can any experts fix my code please!?! #include #include #include void remove_new_line(char* str); int main(int argc, char* argv[]) { if(argc 3) { printf(Too many arguments

Can any experts fix my code please!?!

#include #include #include

void remove_new_line(char* str);

int main(int argc, char* argv[]) { if(argc <= 1) { printf("No arguments "); return 0; } else if(argc < 3) { printf("Not enough arguments "); return 0; } else if(argc > 3) { printf("Too many arguments "); return 0; } if(strlen(argv[1]) != strlen(argv[2])) { printf("Invalid arguments "); return 0; } else if(strlen(argv[1]) == strlen(argv[2])) { char input[100]; char* token; char* temp[100]; int i; fgets(input, sizeof(input), stdin); remove_new_line(input); token = strtok(input, " "); while(token != NULL) { temp[i++] = token; token = strtok(NULL, " "); } for(int j =0; j < i; j++) { if(strcat(temp[j], argv[1])) { temp[j] = argv[2]; printf("%s ", temp[j]); } } } }

void remove_new_line(char* str) { char* p; if (p = strchr(str, ' ')) { *p = '\0'; } }

The purpose is to replace letters in the user input from argv[1] to argv[2].. can someone please fix this codes?

For example, if I compile it, ./tr.c abc def

and the input is,

./tr xy XY 
xxyyxx Lorem ipsum dolor sit amet xxyyxx 

the output should be:

XXYYXX Lorem ipsum dolor sit amet XXYYXX 

and also, please explain me the purpose of using remove_new_line!

Thanks!

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!