Makefile
This commit is contained in:
commit
356bb5cb9e
4 files changed
+28
-14
No files matched your search
+19
-8
@@ -1,30 +1,41 @@
|
||||
#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 puffer[MAX_WORD_LEN];
|
||||
char *teiler = " ,;\n";
|
||||
char puffer[MAX_LINE_NUMBER][MAX_LINE_LEN];
|
||||
char *teiler = "\n ,;";
|
||||
char *token;
|
||||
unsigned int wordCount = 0;
|
||||
int i = 0;
|
||||
unsigned int wordCount = 0;
|
||||
|
||||
fgets(puffer, MAX_LINE_LEN, file);
|
||||
while(fgets(puffer[i], MAX_LINE_LEN, file) != NULL)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
token = strtok(puffer, teiler);
|
||||
i = 0;
|
||||
|
||||
token = strtok(puffer[i], teiler);
|
||||
|
||||
while(token != NULL && wordCount < maxWordCount)
|
||||
{
|
||||
strncpy(words[wordCount], token, MAX_WORD_LEN -1);
|
||||
words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
||||
//words[wordCount][MAX_WORD_LEN - 1] = '\0';
|
||||
|
||||
wordCount++;
|
||||
|
||||
token =strtok(NULL, teiler);
|
||||
token = strtok(NULL, teiler);
|
||||
|
||||
if(token == NULL && i < MAX_LINE_NUMBER)
|
||||
{
|
||||
token = strtok(puffer[i+1], teiler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user