Write a program that reads two strings from the command line. The user should have the possibility of: a) Concatenating the two strings (4p) NOTE: Use strcat from the C library. b) Comparing two strings. (6p) Implement your own strcmp function. NOTE: It is not allowed to use any function from the C string library. //My    code#include #include  int my_strcmp(const char *, const char *);int main(){  char a[100], b[100];   printf(‘Enter the first stringn’);  gets(a);   printf(‘Enter the second stringn’);  gets(b);   strcat(a,b);   printf(‘String obtained on concatenation is %sn’,a);     if(my_strcmp(a,b) == 0)printf(‘word1 %s and word2 %s are equaln’, a, b);elseprintf(‘word1 %s and word2 %s are not equaln’, a,b);return 0;}// own strcmp implementation// if the strings are the same, the functions returns 0// otherwise 1int my_strcmp(const char *s1, const char *s2){while((*s1 != ‘’) && (*s2 != ‘’) && (*s1 == *s2)){s1++;s2++;} if(*s1 != *s2)return 1;return 0;}

Leave a Reply

Your email address will not be published.