A program that reads two strings from the command line

Oct 19th, 2014
Price: $15 USD

Question description

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 string\n");
  printf("Enter the second string\n");
  printf("String obtained on concatenation is %s\n",a);
  if(my_strcmp(a,b) == 0)
printf("word1 %s and word2 %s are equal\n", a, b);
printf("word1 %s and word2 %s are not equal\n", 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 != '\0') && (*s2 != '\0') && (*s1 == *s2))

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

Tutor Answer

(Top Tutor) Taras K
School: University of Virginia

Studypool has helped 1,244,100 students

Review from student
" Goes above and beyond expectations ! "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1824 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors