cmp function in c code example

Example 1: strcmp c

// use: strcmp(string1, string2);

string a = "words";
string b = "words";

if (strcmp(a, b) == 0)
{
	printf("a and b match");
  	// strcmp returns 0 if both strings match
}

else
{
	printf("a and b don't match");
  	// strcmp returns anything else if the strings dont match
}

Example 2: %.*s in c

example:
printf("%.*s",3,"hello");

output:hel
here 3 represents the length of the string to be printed in the "hello string".

Example 3: strcmp c library

#include <string.h>

Example 4: fail() in c++

#include <iostream>
using namespace std;

int main()
{
    int number;
    do{
        cin >> number;
        if(cin.fail())
            cout << "Not a number " << endl;
    }while(!cin.fail());
    cout << "number is " << number << endl;
    system("pause");
    return 0;
}