implemented return value
This commit is contained in:
1 parent
d61687f8df
commit
a02b363e20
2 files changed
+31
No files matched your search
@@ -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++){
|
for (int i = 0; i < (int)len; i++){
|
||||||
salad[x][y+i] = currentWord[i];
|
salad[x][y+i] = currentWord[i];
|
||||||
}
|
}
|
||||||
|
placedWords++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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++){
|
for (int i = 0; i < (int)len; i++){
|
||||||
salad[x+1][y] = currentWord[i];
|
salad[x+1][y] = currentWord[i];
|
||||||
}
|
}
|
||||||
|
placedWords++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return placedWords;
|
return placedWords;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user