Test input.c

This commit is contained in:
Sven Hofmann 2025-11-01 16:01:17 +01:00
parent 39f3febc4f
commit 6b80b5f1cb
3 changed files with 44 additions and 5 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"input.h": "c"
}
}

View File

@ -8,5 +8,5 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
}

View File

@ -1,6 +1,40 @@
#include <stdio.h>
#include "input.h"
#include <string.h>
#include <ctype.h>
int main(){
printf("Hello Patric \n");
return 0;
// 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;
}
}