implemented return value

This commit is contained in:
sengpielto106561 committed 2026-10-25 15:44:45 +01:00
1 parent d61687f8df
commit a02b363e20
3 files changed
+33 -2

No files matched your search

+3 -1
View File
@@ -69,6 +69,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for (int i = 0; i < (int)len; i++){
salad[x][y+i] = currentWord[i];
}
placedWords++;
break;
}
@@ -83,7 +84,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
break;
}
}
//if not all spaces are empty try again
if(cont) continue;
@@ -91,6 +92,7 @@ int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsi
for (int i = 0; i < (int)len; i++){
salad[x+1][y] = currentWord[i];
}
placedWords++;
}
}
return placedWords;
+29
View File
@@ -0,0 +1,29 @@
//Torbens Kopie
#include "input.h"
#include <string.h>
#include <ctype.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char *tmp;
int counter = 0;
const char delimiters[] = ",!.;:? "
while(fgets(tmp, MAX_WORD_LEN, flie) != NULL){
char *token = strtok_r (tmp, delimiters, &delimiters);
if(strncpy(words[counter], token, MAX_WORD_LEN) == NULL){
//failure
return -1;
}
counter++;
while(token != NULL){
token = strtpk_r (NULL, delimiters, &delimiters);
strncpy(words[counter], token, MAX_WORD_LEN);
counter++;
}
}
return counter;
}
+1 -1
View File
@@ -8,5 +8,5 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
}