Merge pull request 'vaisse' (#1) from vaisse into master

Reviewed-on: #1
This commit is contained in:
2025-10-08 14:24:49 +02:00
2 changed files with 87 additions and 0 deletions

80
getfuncs.c Normal file
View File

@@ -0,0 +1,80 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/*
*/
int getFileLength(){
/*variables*/
FILE* stream;
int file_length = 0;
char* line = NULL;
size_t length = 0;
ssize_t read;
/*prog*/
stream = fopen("wordbank.txt", "r");
if (stream == NULL){
return EXIT_FAILURE;
}
while((read = getline(&line, &length, stream)) != -1){
file_length++;
}
fclose(stream);
return file_length-1;
}
/*
*/
int fetchWord(char* fullword, int file_length){
/*variables*/
FILE* stream;
int random = (rand() * time(NULL)) % (file_length);
char read[8];
unsigned int counter = 0;
int char_size = (int) sizeof(char);
int line=0;
int offset=0;
/*prog*/
printf("%d\n", random);
stream = fopen("wordbank.txt", "r");
if (stream == NULL){
return -1;
}
while((!feof(stream))&&(offset!=random)){
fread(read, sizeof(char), 1, stream);
if(*read=='\n'){
offset++;
}
}
*read=' ';
while(*read!='\n'){
fread(read, sizeof(char), 1, stream);
fullword[counter] = *read;
counter++;
}
fclose(stream);
return 0;
}
/*
int main(void){
int flength;
char fullword[128];
flength = getFileLength();
if(fetchWord(fullword, flength)!=-1){
printf("%s", fullword);
}
return EXIT_SUCCESS;
}*/

7
wordbank.txt Normal file
View File

@@ -0,0 +1,7 @@
anticonstitutionnellement
éclésiastique
abandonner
seringue
vocifération
éponyme