generated from freudenreichan/info2Praktikum-Wortsalat
nput änderung
This commit is contained in:
parent
eaa16ed84c
commit
212bb6e46f
@ -1,12 +1,34 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdio.h> //fürs öffnen FILE
|
||||||
|
|
||||||
// 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
|
||||||
|
|
||||||
|
#define MAX_WORD_LENGTH 100 //ka ob man dass muss
|
||||||
|
|
||||||
|
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
FILE *quelle; //Zeiger auf quelle
|
||||||
|
|
||||||
|
quelle = fopen("words.txt", "r"); //quelle definieren (Datei öffnen)
|
||||||
|
|
||||||
|
|
||||||
|
if (quelle==0) //Dateiöffnen geklappt?
|
||||||
|
{
|
||||||
|
printf("File not found\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fgets(words, MAX_WORD_LEN, quelle);
|
||||||
|
|
||||||
|
|
||||||
|
fclose(quelle); //Datei schließen
|
||||||
|
|
||||||
|
return words; //string zurückgeben
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user