Template
Compare commits
4
Commits
main
...
84e854fdc2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84e854fdc2 | ||
|
|
d5be49e0ff | ||
|
|
8c4e01b75c | ||
|
|
20496fdfba |
No files matched your search
@@ -1,12 +0,0 @@
|
||||
#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)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "game.h"
|
||||
#include "input.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -13,5 +14,15 @@
|
||||
// Creates the word salad by placing words randomly and filling empty spaces
|
||||
int createWordSalad(char salad[MAX_SEARCH_FIELD_LEN][MAX_SEARCH_FIELD_LEN], unsigned int searchFieldLen, const char words[][MAX_WORD_LEN], unsigned int wordCount)
|
||||
{
|
||||
srand(time(NULL));
|
||||
char bustaben[] = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
|
||||
char zufall = bustaben[rand() % 26];
|
||||
|
||||
printf("Zufaelliger Bustabe: %c\n", zufall);
|
||||
|
||||
const char words[15][MAX_WORD_LEN] = "Yeti,Nessie,Werwolf,Vampir,Monster,Hydra,Frankenstein,Dracula,KingKong,Gremlin,Kobold,Hexe,Poltergeist,Gespenst,Oge";
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,56 @@
|
||||
#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)
|
||||
{
|
||||
int wordCount = 0;
|
||||
char line[MAX_LINE_LEN];
|
||||
|
||||
while (fgets(line, MAX_LINE_LEN, file)) {
|
||||
char currentWord[MAX_LINE_LEN];
|
||||
int wordPos = 0;
|
||||
|
||||
for ( int i = 0; line[i] != '\0'; i++) {
|
||||
if (line[i] == ',' || line[i] == ';' || line[i] == ' ' || line[i] == '\n') {
|
||||
|
||||
if (wordPos > 0) {
|
||||
|
||||
currentWord[wordPos] = '\0';
|
||||
|
||||
if (wordCount < maxWordCount) {
|
||||
|
||||
strcpy(words[wordCount], currentWord);
|
||||
wordCount++;
|
||||
}
|
||||
wordPos = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (wordPos < MAX_WORD_LEN-1) {
|
||||
|
||||
currentWord[wordPos] = toupper(line[i]);
|
||||
wordPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wordPos > 0) {
|
||||
|
||||
currentWord[wordPos] = '\0';
|
||||
|
||||
if (wordCount < maxWordCount) {
|
||||
|
||||
strcpy(words[wordCount], currentWord);
|
||||
wordCount++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return wordCount;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user