A program that reads two strings from the command line

A program that reads two strings from the command line

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 <stdio.h>
#include <string.h>
 

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);
else
printf(“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 1
int my_strcmp(const char *s1, const char *s2)
{
while((*s1 != ‘’) && (*s2 != ‘’) && (*s1 == *s2))
{
s1++;
s2++;
}

if(*s1 != *s2)
return 1;
return 0;

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper