This commit is contained in:
vaisse
2025-10-08 11:56:36 +02:00
parent d074170b0f
commit 0a7067acc3
2 changed files with 80 additions and 0 deletions

73
getfuncs.c Normal file
View File

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

7
wordbank.txt Normal file
View File

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