mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 14:59:36 +03:00
45 lines
1.0 KiB
C
45 lines
1.0 KiB
C
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
/*
|
|
is_isogram: returns true if the given string a isogram, otherwise false.
|
|
*/
|
|
bool is_isogram(const char phrase[])
|
|
{
|
|
/* use 'unsigned' because of the function strlen(...) */
|
|
unsigned int i = 0;
|
|
unsigned int j = 0;
|
|
|
|
/* the current read character in the first for-loop */
|
|
char current_char = ' ';
|
|
|
|
/* return status */
|
|
bool status = true;
|
|
|
|
/* contains the length of the given string */
|
|
unsigned int len_phrase = strlen(phrase);
|
|
|
|
for (i = 0; i < len_phrase; i++)
|
|
{
|
|
current_char = phrase[i];
|
|
|
|
/* makes sure the current character has no repetition */
|
|
for (j = i + 1; j < len_phrase; j++)
|
|
{
|
|
if (current_char == phrase[j])
|
|
{
|
|
status = false;
|
|
|
|
/*
|
|
because the given string is none isogram.
|
|
that means we can exit the nested for-loop.
|
|
*/
|
|
goto end;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* exit label */
|
|
end:
|
|
return status;
|
|
} |