Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tests.out
test_prg
12 changes: 12 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
output: main.o isogram.o
gcc main.o isogram.o -o isogram

main.o: main.c
gcc -c main.c -o main.o

isogram.o: isogram.c isogram.h
gcc -c isogram.c

clean:
rm -rf main.o isogram.o isogram

20 changes: 17 additions & 3 deletions src/isogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@


bool is_isogram(const char phrase[]){
// this is the documentation
if (false) {
printf("hello world\n");
int i = 0;
int freq[256] = {0};
while (phrase[i] != '\0'){
char c = phrase[i];
freq[c]++;
i++;
}
int max = 0;
for (int i = 0; i < 256 ; i++){
if (freq[i] != 0) {
// first time?
if (max == 0){
max = freq[i]; // keep track of the real frequenz
} else if (freq[i] != max){
return false;
}
}
}
return true;
}
Binary file added src/isogram.h.gch
Binary file not shown.
11 changes: 11 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "isogram.h"
#include <stdio.h>

int main(int arg, char *argv[]){
if (is_isogram(argv[1])){
printf("The Pharse is an isogram.\n");
}else {
printf("The pharse is not an isogram.\n");
}
return 0;
}
31 changes: 31 additions & 0 deletions src/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#define UNITY_OUTPUT_COLOR

#include "isogram.h"
#include <string.h>
#include <stdio.h>


bool is_isogram(const char phrase[]){

int i = 0;
int freq[256] = {0};

while(phrase[i] != '\0'){
char c = phrase[i];
freq[c]++;
i++;
}
int max = 0;
for (int i = 0; i<256; i++) {
if (freq[i] != 0) {
//first time
if(max == 0) {
max = freq[i];
} else if(freq[i] != max) {
return false;
}
}
}

return true;
}
Binary file added test_prg
Binary file not shown.