Client Login Register
Calculate Price & Order →
← Back to all articles

A program that reads two strings from the command line

Published on December 02, 2026 • Category: Academic
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; }




Share

We only email you; unsubscribe in one click. No address is ever sold.

Ask about study support 💬 WhatsApp 📞

Just now