top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

what value return strcmpi()?

+1 vote
736 views

Give me with example.

posted May 14, 2016 by Hasan Raza

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

strcmpi( ) function in C is same as strcmp() function. But, strcmpi( ) function is not case sensitive. i.e, “A” and “a” are treated as same characters. Where as, strcmp() function treats “A” and “a” as different characters.

Both functions compare two given strings and returns zero if they are same.
If length of string1 < string2, it returns < 0 value. If length of string1 > string2, it returns > 0 value. Syntax for strcmp( ) function is given below.

int strcmpi ( const char * str1, const char * str2 );

example:

strcmpi("ABC","abc");
[Here, 
first comparison: A==a
second comparison: B==b
Thired comparison: C==c
So result = 0]

illustrate strcmpi() C program:

#include<stdio.h>
int main()
{
 int r;
 char str1[40],str2[40];
 printf("Enter first string : ");
 gets(str1);
 printf("Enter second string : ");
 gets(str2);
 r = strcmpi(str1,str2);
 printf("Result : %d",r);
 getch();
 return 0;
}
answer May 20, 2016 by Rupali Dadhe
Yes, you right.
Thanks.
+1 vote

//Output will 0 if both string is equal
//Output will be -1 if first string is less to second
//Output will be 1 if first string is gretter to second

#include<string.h>
#include<stdio.h>

int main()
{

char a[105],b[105];

gets(a);
gets(b);

printf("%d",strcmpi(a,b));

}
answer May 14, 2016 by Rajan Paswan
Similar Questions
+1 vote

I have a string array that contains 20 words. I made a function that take 1 random word from the array. But I want to know how can I return that word from array. Right now I am using void function, I had used char type but it wont work.
Please help here? Need to make word guessing game.

#include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <string>
using namespace std;

void random(string names[]);

int main() {
     char a;
     string names[] = {"vergs", "rokas", "metrs", "zebra", "uguns", "tiesa", "bumba",
                       "kakls", "kalns", "skola", "siers", "svari", "lelle", "cimdi",
                       "saule", "parks", "svece", "diegs", "migla", "virve"};

    random(names);

    cout<<"VARDU MINESANAS SPELE"<<endl;
    cin>>a;

    return 0;
}

void random(string names[]){
    int randNum;
    for (int i = 0; i < 20; i++) { /// makes this program iterate 20 times; giving you 20 random names.
       srand( time(NULL) ); /// seed for the random number generator.
       randNum = rand() % 20 + 1; /// gets a random number between 1, and 20.
       names[i] = names[randNum];
    }

    //for (int i = 0; i < 1; i++) {
      //cout << names[i] << endl; /// outputs one name.
    //}
}
+3 votes

A number is called as a Jumping Number if all adjacent digits in it differ by 1. The difference between ‘9’ and ‘0’ is not considered as 1.
All single digit numbers are considered as Jumping Numbers. For example 7, 8987 and 4343456 are Jumping numbers but 796 and 89098 are not.

Given a positive number x, print all Jumping Numbers smaller than or equal to x. The numbers can be printed in any order.

Example:

Input: x = 20
Output: 0 1 2 3 4 5 6 7 8 9 10 12

Input: x = 105
Output: 0 1 2 3 4 5 6 7 8 9 10 12
21 23 32 34 43 45 54 56 65
67 76 78 87 89 98 101

Note: Order of output doesn't matter,
i,e., numbers can be printed in any order

+3 votes
#include <stdio.h>
int main()
{
    char vowels[5]={'a','e','i','o','u'};
    int x;

    printf("Vowel Letters");
    for(x=0;x<=5;x++)
    {
         printf("\n %C",vowels[x]);
    }
}

Output

Vowel Letters
a
e
i
o
u
♣
Process exited after 0.1132 seconds with return value 3

What is the meaning of return value 3

...