TheAlgorithms-C/exercism/isogram/isogram.c

45 lines
1.0 KiB
C
Raw Normal View History

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.
*/
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);
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 */
for (j = i + 1; j < len_phrase; j++)
2018-01-25 00:24:43 +03:00
{
if (current_char == phrase[j])
{
status = false;
/*
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;
}
}
}
/* exit label */
end:
return status;
2018-01-25 00:24:43 +03:00
}