Test input.c
This commit is contained in:
parent
39f3febc4f
commit
6b80b5f1cb
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"input.h": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,40 @@
|
|||||||
#include <stdio.h>
|
#include "input.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
int main(){
|
int main(){
|
||||||
printf("Hello Patric \n");
|
// 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)
|
||||||
|
{
|
||||||
|
int zeilen = 0;
|
||||||
|
int spalten = 0;
|
||||||
|
file = fopen("words.txt", "r");
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
printf("Fehler beim öffnen der Wörter \n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
while(fgets(words[zeilen], MAX_WORD_LEN, file) != NULL)
|
||||||
|
{
|
||||||
|
int laenge = strlen(words[spalten]);
|
||||||
|
if (words[zeilen][laenge - 1] == '\n')
|
||||||
|
words[zeilen][laenge - 1] = '\0';
|
||||||
|
spalten++;
|
||||||
|
zeilen++;
|
||||||
|
}
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
for (int i = 0; i < zeilen; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < spalten; j++)
|
||||||
|
{
|
||||||
|
printf("%c", words[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("finished");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user