Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #define MAX 100 char * concat(char * s1, char * s2); int main(int argc, char * argv[]){ char s1[] = Fun; char

image text in transcribed

#include #include #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 HotPotato

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

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

More Books

Students also viewed these Databases questions

Question

Using Language That Works

Answered: 1 week ago

Question

4. Are my sources relevant?

Answered: 1 week ago