2018-01-25 00:24:43 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
is_isogram: returns true if the given string a isogram, otherwise false.
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
bool is_isogram(const char phrase[])
|
2018-01-25 00:24:43 +03:00
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
for (i = 0; i < len_phrase; i++)
|
2018-01-25 00:24:43 +03:00
|
|
|
{
|
|
|
|
current_char = phrase[i];
|
|
|
|
|
|
|
|
/* makes sure the current character has no repetition */
|
2020-05-29 23:23:24 +03:00
|
|
|
for (j = i + 1; j < len_phrase; j++)
|
2018-01-25 00:24:43 +03:00
|
|
|
{
|
|
|
|
if (current_char == phrase[j])
|
|
|
|
{
|
|
|
|
status = false;
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
/*
|
2018-01-25 00:24:43 +03:00
|
|
|
because the given string is none isogram.
|
|
|
|
that means we can exit the nested for-loop.
|
|
|
|
*/
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
/* exit label */
|
|
|
|
end:
|
|
|
|
return status;
|
2018-01-25 00:24:43 +03:00
|
|
|
}
|