Add creation of Gap_sentence TODO: Add lenght value to Gap_sentence

This commit is contained in:
XOR 2022-11-08 22:51:14 +01:00
parent 45af1fd41f
commit aaeac6d467
2 changed files with 59 additions and 10 deletions

BIN
Aufgabe 1/main Executable file

Binary file not shown.

View file

@ -1,5 +1,5 @@
#include <stdio.h>
//#include <stdlib.h>
#include <stdlib.h>
#define SIZEOFARR(a) (sizeof(a)/sizeof(a[0]))
@ -16,6 +16,13 @@ unsigned short int arrContains(char checkForVal, char *checkInArr, int arrSize)
return 0;
}
struct Gap_sentence
{
char words[100][50];
__uint8_t gapsizes[100];
};
int main(int argc, char const *argv[])
{
char words[30000][20];
@ -31,8 +38,8 @@ int main(int argc, char const *argv[])
}
int word = 0;
int character = 0;
int word_index = 0;
int character_index = 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);
@ -48,23 +55,65 @@ int main(int argc, char const *argv[])
{
if (word_found)
{
word++;
character = 0;
word_index++;
character_index = 0;
word_found = 0;
}
}
else{
word_found = 1;
words[word][character]=curr_char;
character++;
words[word_index][character_index]=curr_char;
character_index++;
}
}
for(int i=0; i<=word;i++){
fprintf(fpp,"%s ", words[i]);
printf("%s ",words[i]);
//Get sentence with gap
FILE *gap_file;
struct Gap_sentence gap_sentence;
gap_file = fopen("/home/xor/coding/BwInf_41_1/Aufgabe 1/stoerung0.txt","r");
word_index = 0;
character_index = 0;
word_found = 0;
short int file_read = 0;
while(!file_read){
char curr_char = fgetc(gap_file);
switch (curr_char)
{
case EOF:
file_read = 1;
break;
case ' ':
/*only begin a new word, if the last characters were part of a word
or if the next character is part of a word as we dont want to save the next word in the index where
the last underscores were counted (and therefore word_index was not increased)*/
if(word_found || *gap_file->_IO_read_ptr != '_')
{
word_index++;
word_found=0;
character_index = 0;
}
break;
case '_':
gap_sentence.gapsizes[word_index]++;
break;
default:
word_found = 1;
gap_sentence.words[word_index][character_index] = curr_char;
character_index++;
break;
}
}
for (int i = 0; i < 10; i++)
{
printf("%s | ",gap_sentence.words[i]);
printf("%d\n",gap_sentence.gapsizes[i]);
}
return 0;