#include <stdio.h>
#include <stdlib.h>
int main(void) 
{   char code[15];
    
    printf("\n\tEnter the code >>> ");
    scanf("%s", code);
    if(code=="checkif")
        printf("\n\t Correct");
    else
        printf("\n\tIncorrect");
}
            Asked
            
        
        
            Active
            
        
            Viewed 148 times
        
    0
            
            
         
    
    
        Rup
        
- 33,765
- 9
- 83
- 112
 
    
    
        Juhász Koppány
        
- 23
- 4
- 
                    2you want `strcmp()`. But some may suggest the `strncmp()` function as it compares not more than n characters. The `man` pages are excellent for these C apis ( `man strcmp` from the command line ). – rustyMagnet Dec 14 '20 at 09:22
- 
                    3Does this answer your question? [How do I properly compare strings in C?](https://stackoverflow.com/questions/8004237/how-do-i-properly-compare-strings-in-c) – kyriakosSt Dec 14 '20 at 09:23
1 Answers
0
            
            
        You use the function strcmp exist in the header #include <string.h> to compare between two strings
#include <string.h>
#include <stdio.h>
int main(void)
{   char code[15];
    printf("\n\tEnter the code >>> ");
    scanf("%[^\n]s", code);
    if(strcmp(code,"checkif")==0)
    printf("\n\t Correct");
    else
    printf("\n\tIncorrect");
}
 
    
    
        MED LDN
        
- 684
- 1
- 5
- 10