Lowercase letters that did not appear in the array, in order [closed]

We, beginners, should help each other.

If the function deals with strings then the second parameter of the function is redundant.

A straightforward approach without using standard containers as for example std::set can look the following way

#include <iostream>

void missing( const char s[] ) 
{
    const char *letter = "abcdefghijklmnopqrstuvwxyz";

    for ( size_t i = 0; letter[i] != '\0'; i++ )
    {
        size_t j = 0;

        while ( s[j] != '\0' and s[j] != letter[i] ) j++;

        if ( s[j] == '\0' ) std::cout << letter[i];
    }        
}

int main()
{
    while ( true )
    {        
        const size_t N = 100;
        char s[N];

        std::cout << "Enter a sentence: ";

        if ( not std::cin.getline( s, N ) or s[0] == '\0' ) break;

        missing( s );

        std::cout << '\n';
    }        
}

The program output might look like

Enter a sentence: Article 1: All human beings are born free and equal in dignity and rights
jkpvwxz
Enter a sentence:

Browse More Popular Posts

Leave a Comment