Finish task with buggy code
This commit is contained in:
parent
aaeac6d467
commit
bf36f1a5c7
5 changed files with 1751 additions and 13 deletions
1
Aufgabe 1/foostoerung.txt
Normal file
1
Aufgabe 1/foostoerung.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
im wunderland von lewis
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
open the text
|
open the text .
|
||||||
make a list with every word
|
make a list with every word .
|
||||||
|
|
||||||
get input
|
get input .
|
||||||
list with word or distance to next defined word
|
list with word or distance to next defined word .
|
||||||
|
|
||||||
look at first word of input
|
look at first word of input
|
||||||
find first occurance
|
find first occurance
|
||||||
|
|
|
||||||
BIN
Aufgabe 1/main
BIN
Aufgabe 1/main
Binary file not shown.
|
|
@ -1,9 +1,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "../libs/utf8.h"
|
||||||
|
|
||||||
#define SIZEOFARR(a) (sizeof(a)/sizeof(a[0]))
|
#define SIZEOFARR(a) (sizeof(a)/sizeof(a[0]))
|
||||||
|
|
||||||
char allowedChars[] = "aäbcdefghijklmnoöpqrstuüvwxyzAÄBCDEFGHIJKLMNOÖPQRSTUÜVWXYZß \n";
|
char allowedChars[] = "aäbcdefghijklmnoöpqrstuüvwxyzAÄBCDEFGHIJKLMNOÖPQRSTUÜVWXYZß1234567890 \n";
|
||||||
|
|
||||||
unsigned short int arrContains(char checkForVal, char *checkInArr, int arrSize)
|
unsigned short int arrContains(char checkForVal, char *checkInArr, int arrSize)
|
||||||
{
|
{
|
||||||
|
|
@ -20,9 +22,11 @@ struct Gap_sentence
|
||||||
{
|
{
|
||||||
char words[100][50];
|
char words[100][50];
|
||||||
__uint8_t gapsizes[100];
|
__uint8_t gapsizes[100];
|
||||||
|
short unsigned int length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char const *argv[])
|
int main(int argc, char const *argv[])
|
||||||
{
|
{
|
||||||
char words[30000][20];
|
char words[30000][20];
|
||||||
|
|
@ -74,7 +78,6 @@ int main(int argc, char const *argv[])
|
||||||
struct Gap_sentence gap_sentence;
|
struct Gap_sentence gap_sentence;
|
||||||
gap_file = fopen("/home/xor/coding/BwInf_41_1/Aufgabe 1/stoerung0.txt","r");
|
gap_file = fopen("/home/xor/coding/BwInf_41_1/Aufgabe 1/stoerung0.txt","r");
|
||||||
|
|
||||||
word_index = 0;
|
|
||||||
character_index = 0;
|
character_index = 0;
|
||||||
word_found = 0;
|
word_found = 0;
|
||||||
short int file_read = 0;
|
short int file_read = 0;
|
||||||
|
|
@ -91,30 +94,74 @@ int main(int argc, char const *argv[])
|
||||||
the last underscores were counted (and therefore word_index was not increased)*/
|
the last underscores were counted (and therefore word_index was not increased)*/
|
||||||
if(word_found || *gap_file->_IO_read_ptr != '_')
|
if(word_found || *gap_file->_IO_read_ptr != '_')
|
||||||
{
|
{
|
||||||
word_index++;
|
gap_sentence.length++;
|
||||||
word_found=0;
|
word_found=0;
|
||||||
character_index = 0;
|
character_index = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '_':
|
case '_':
|
||||||
gap_sentence.gapsizes[word_index]++;
|
gap_sentence.gapsizes[gap_sentence.length]++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
word_found = 1;
|
word_found = 1;
|
||||||
gap_sentence.words[word_index][character_index] = curr_char;
|
gap_sentence.words[gap_sentence.length][character_index] = curr_char;
|
||||||
character_index++;
|
character_index++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//After the last word, there is no space, so weed need to add one length
|
||||||
|
gap_sentence.length++;
|
||||||
|
fclose(gap_file);
|
||||||
|
|
||||||
|
unsigned int occurance_index = 0;
|
||||||
|
int sentence_occurances[100];
|
||||||
|
int sentence_occurance_index = 0;
|
||||||
|
|
||||||
|
while(occurance_index<sizeof(words)/sizeof(words[0]))
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
{
|
{
|
||||||
printf("%s | ",gap_sentence.words[i]);
|
//find next occurance of first word
|
||||||
printf("%d\n",gap_sentence.gapsizes[i]);
|
while(1){
|
||||||
|
if(utf8casecmp(gap_sentence.words[0],words[occurance_index])==0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(occurance_index>sizeof(words)/sizeof(words[0])){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
occurance_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 1; i<gap_sentence.length;i++)
|
||||||
|
{
|
||||||
|
if(gap_sentence.gapsizes[i]==0)
|
||||||
|
{
|
||||||
|
if(utf8casecmp(gap_sentence.words[i],words[i+occurance_index])!=0)
|
||||||
|
{
|
||||||
|
goto nomatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// -1 because i gets increased by 1 after 'continue'
|
||||||
|
i += gap_sentence.gapsizes[i]-1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sentence_occurances[sentence_occurance_index] = occurance_index;
|
||||||
|
sentence_occurance_index++;
|
||||||
|
nomatch:
|
||||||
|
//We know the current first word to be matching, so no need to check it again
|
||||||
|
occurance_index++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int j = 0; j<=sentence_occurance_index;j++)
|
||||||
|
{
|
||||||
|
for (int i=0;i<gap_sentence.length;i++){
|
||||||
|
printf("%s ",words[sentence_occurances[j]+i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
1690
libs/utf8.h
Normal file
1690
libs/utf8.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue