forked from menault/TD3_DEV51_Qualite_Algo
sa pue
This commit is contained in:
73
getfuncs.c
Normal file
73
getfuncs.c
Normal 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
7
wordbank.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
anticonstitutionnellement
|
||||||
|
éclésiastique
|
||||||
|
abandonner
|
||||||
|
seringue
|
||||||
|
vocifération
|
||||||
|
éponyme
|
||||||
|
|
||||||
Reference in New Issue
Block a user