forked from TheAlgorithms/C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisogram.c
45 lines (37 loc) · 1.04 KB
/
isogram.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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;
}