cmp function in c code example
Example 1: strcmp c
string a = "words";
string b = "words";
if (strcmp(a, b) == 0)
{
printf("a and b match");
}
else
{
printf("a and b don't 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;
}