The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <string.h>
#include <conio.h>
void main()
{
clrscr();
char str1[30] = "Help for coders.";
char str2[30] = "Help for coders.";
char str3[30] = "help for coders.";
int compare;
compare = strcmp(str1, str2); //Returns 0(zero) if finds exact match
cout << "strcmp for str1 & str2 is: " << compare;
compare = strcmp(str3, str1); //Returns 1(one) if does not finds exact match
cout << "\nstrcmp for str3 & str1 is: " << compare;
getch();
}
//........Coded by YASH ALAPURIA
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(void)
{
system("cls");
char str1[30] = "Help for coders.";
char str2[30] = "Help for coders.";
char str3[30] = "help for coders.";
int compare;
compare = strcmp(str1, str2); //Returns 0(zero) if finds exact match
cout << "strcmp for str1 & str2 is: " << compare;
compare = strcmp(str3, str1); //Returns 1(one) if does not finds exact match
cout << "\nstrcmp for str3 & str1 is: " << compare;
return 0;
}
//........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP