I decided the task in codewars.com which called "Detect Pangram":
A pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence "The quick brown fox jumps over the lazy dog" is a pangram, because it uses the letters A-Z at least once (case is irrelevant).
Given a string, detect whether or not it is a pangram. Return True if it is, False if not. Ignore numbers and punctuation.
So I wrote that code:
main.c:
#include <stdio.h>
#include <stdlib.h>
int is_pangram(char *str)
{
int j = 0; // start counting the number of characters in a string
while (str[j])
{
j++;
} // end counting
for (int i = 0; i < j; i++) // checking all characters in this string on a capital letter
{
if (str[i] >= 65 && str[i] <= 90) // if this character is a capital letter (in the ASCII from 65 to 90),
// we set it to low letter
{
str[i] = (int)str[i] + 32;
}
}
char alphabet[26]; // creating an empty array
int count_add_to_alph = 0; // set a counter for successfull setting a letter to the array
int counter_char = 0; // set a counter for array of characters
while (str[counter_char]) // start checking each character
{
if (str[counter_char] >= 'a' && str[counter_char] <= 'z' && str[counter_char] != alphabet[str[counter_char] - 'a'])
{ // if the number of ASCII of the character is a low letter
// and this letter is not set in alphabet we set this letter
// into an array alphabet
alphabet[str[counter_char] - 'a'] = str[counter_char];
count_add_to_alph++;
}
counter_char++;
} // end checking
for (int i = 0; i < 26; i++) // setting each character to 0
{
alphabet[i] = 0;
}
if (count_add_to_alph == 26) // if all letters of english alphabet were added to the alphabet array,
// we return true, else false
{
return count_add_to_alph;
}
else
{
return 0;
}
}
I started testing that in codewars and it returned me that:
Test Results:
Example_Tests
should_pass_all_the_tests_provided
Test Crashed
Caught unexpected signal: SIGSEGV (11). Invalid memory access.
Completed in 0.0000ms