Question
#include #include #include #define MAX 100 char * concat(char * s1, char * s2); int main(int argc, char * argv[]){ char s1[] = Fun; char
#include
#define MAX 100
char * concat(char * s1, char * s2);
int main(int argc, char * argv[]){ char s1[] = "Fun"; char s2[MAX]; //Assume fgets gets some valid input fgets(s2,MAX,stdin); int len = strlen(s2); //Remove newline if it exists if(len > 0 && s2[len-1] == ' '){ s2[len-1] = '\0'; } char * s3 = concat(s1,s2); char * s4 = concat(s2,s1); char * s5 = concat("",s2); char * s6 = concat(s2,""); char * s7 = concat(s3,s3); printf("s1: %s ",s1); printf("s2: %s ",s2); printf("s3: %s ",s3); printf("s4: %s ",s4); printf("s5: %s ",s5); printf("s6: %s ",s6); printf("s7: %s ",s7); free(s3); free(s4); free(s5); free(s6); free(s7); return EXIT_SUCCESS; }
char * concat(char * s1, char * s2){ //TO DO }
This file has a main function that you must NOT modify. You lab task is to implement the function char * concat (char s1, char *s2); This function should return a string that concatenations (joins) s1 and s2 together. It must not modify the contents of s1 or s2. For example if I called the function and then printed the result as follows char *s-concat ("Hot" , "Potato") printf("%s", s) ; I would get the output HotPotatoStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started