Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to COmpare Strings

0 votes
asked Dec 29, 2017 by [email protected]
check this program

#include <stdio.h>

int main()
    char option[20];
    printf(" Y-Yes       N-No \n");
        scanf("%s", &option);

            if (strcmp(option) == "Y" );
                printf("Its a yes \n");}
             printf("Its no \n %s", option);}

    return 0;

1 Answer

0 votes
answered Jan 5, 2018 by Help4fun
You didn't compare anything here, strcmp is used to compare two strings in their order in alphabete.

For example:

 char a[]="Learn this";
 char b[]="Learn tzis";

printf("%d",strcmp(a,b));  ==>> -1, because 'h' appears faster in the aphabete than 'z'

If 'h' would appear after 'z' in the alphabete, after printf you'd have get 1, and if the two strings were the same, no letters changed, you'd have get 0.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.