Add creation of word list
This commit is contained in:
parent
55a65ebec9
commit
45af1fd41f
10 changed files with 3791 additions and 0 deletions
71
Aufgabe 1/main.c
Normal file
71
Aufgabe 1/main.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
|
||||
#define SIZEOFARR(a) (sizeof(a)/sizeof(a[0]))
|
||||
|
||||
char allowedChars[] = "aäbcdefghijklmnoöpqrstuüvwxyzAÄBCDEFGHIJKLMNOÖPQRSTUÜVWXYZß \n";
|
||||
|
||||
unsigned short int arrContains(char checkForVal, char *checkInArr, int arrSize)
|
||||
{
|
||||
for (int i = 0;i<arrSize;i++)
|
||||
{
|
||||
if(checkForVal==checkInArr[i]){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
char words[30000][20];
|
||||
FILE *fp;
|
||||
FILE *fpp;
|
||||
fpp = fopen("/home/xor/coding/BwInf_41_1/Aufgabe 1/debug.txt","w");
|
||||
fp = fopen("/home/xor/coding/BwInf_41_1/Aufgabe 1/Alice_im_Wunderland.txt", "r");
|
||||
//fp = fopen("/home/xor/Dokumente/Coding/BwInf_41_1/Aufgabe 1/test.txt", "r");
|
||||
if(fp == NULL||fpp==NULL)
|
||||
{
|
||||
printf("Datei konnte nicht geoeffnet werden.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int word = 0;
|
||||
int character = 0;
|
||||
int word_found = 0; //checks if multiple spaces are behind each other, we don't want to add a new word
|
||||
while(1){
|
||||
char curr_char = fgetc(fp);
|
||||
if(curr_char==EOF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (!arrContains(curr_char,allowedChars,SIZEOFARR(allowedChars)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (curr_char==' '|| curr_char=='\n')
|
||||
{
|
||||
if (word_found)
|
||||
{
|
||||
word++;
|
||||
character = 0;
|
||||
word_found = 0;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
word_found = 1;
|
||||
words[word][character]=curr_char;
|
||||
character++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(int i=0; i<=word;i++){
|
||||
fprintf(fpp,"%s ", words[i]);
|
||||
printf("%s ",words[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue