generated from freudenreichan/info2Praktikum-Wortsalat
input fertig
This commit is contained in:
parent
6a3dd4452a
commit
4299c3979e
@ -1,12 +1,29 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#define MAX_WORD_LEN 100
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
// 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
|
// Read words from file and store in 'words' array
|
||||||
|
int anzahlWoerter = 0;
|
||||||
|
char zeile[500];
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){
|
||||||
|
char *wort[] = strtok(zeile, ",; \n");
|
||||||
|
|
||||||
|
while(wort != NULL && anzahlWoerter <= maxWordCount){
|
||||||
|
strncpy(words[anzahlWoerter], wort, anzahlWoerter -1);
|
||||||
|
words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0';
|
||||||
|
anzahlWoerter++;
|
||||||
|
wort = strtok(NULL, ",; \n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return anzahlWoerter;
|
||||||
}
|
}
|
||||||
@ -1,12 +1,29 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#define MAX_WORD_LEN 100
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
|
// 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
|
// Read words from file and store in 'words' array
|
||||||
|
int anzahlWoerter = 0;
|
||||||
|
char zeile[500];
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){
|
||||||
|
char *wort[] = strtok(zeile, ",; \n");
|
||||||
|
|
||||||
|
while(wort != NULL && anzahlWoerter <= maxWordCount){
|
||||||
|
strncpy(words[anzahlWoerter], wort, anzahlWoerter -1);
|
||||||
|
words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0';
|
||||||
|
anzahlWoerter++;
|
||||||
|
wort = strtok(NULL, ",; \n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return anzahlWoerter;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user