Strcmp() function compares strings until it finds corresponding characters that differ, - C String

C examples for String:String Function

Description

Strcmp() function compares strings until it finds corresponding characters that differ,

Demo Code

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

#define LISTSIZE 6/*  w  w  w  . j  a  v  a  2s .  c  om*/

int main(){

    const char * list[LISTSIZE] ={"a", "b","c", "d","e", "f"};
    int count = 0;
    int i;
    
    for (i = 0; i < LISTSIZE; i++){
        if (strncmp(list[i],"astro", 5) == 0)
        {
            printf("Found: %s\n", list[i]);
            count++;
        }
    }
    printf("The list contained %d words beginning"
           " with astro.\n", count);
    
    return 0;
}

Result


Related Tutorials