Quick actions

cmd+k|ctrl+k

Navigation

Languages

Counting words starting with A-Z

Snippet info

Language

C

Visibility

public

Author

mrsimb

Created

2017-06-19T11:54:51Z

Updated

2017-06-19T17:47:36Z

#include <stdio.h>

int bigFirstLetters(char *string) {
    int words = 0;
    int inWord = 0;
    
    while(string[0]) {
        char c = string[0];
        
        int AZ = (c >= 'A') && (c <= 'Z');
        int az = (c >= 'a') && (c <= 'z');
        
        if (!inWord && AZ) {
            inWord = 1;
        }
        
        if (inWord && !AZ && !az) {
            inWord = 0;
            words++;
        }
        
        string++;
    }
    
    return words;
}

int main(void) {
    char *string = "hello My Dear friend.";
    printf("%d\n", bigFirstLetters(string));
    return 0;
}
INFO