implemented return value
This commit is contained in:
1 parent
d61687f8df
commit
a02b363e20
3 files changed
+33
-2
No files matched your search
@@ -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