diff --git a/getfuncs.c b/getfuncs.c new file mode 100644 index 0000000..b378556 --- /dev/null +++ b/getfuncs.c @@ -0,0 +1,80 @@ +#include +#include +#include + +/* + +*/ +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; +}*/ \ No newline at end of file diff --git a/wordbank.txt b/wordbank.txt new file mode 100644 index 0000000..135d681 --- /dev/null +++ b/wordbank.txt @@ -0,0 +1,7 @@ +anticonstitutionnellement +éclésiastique +abandonner +seringue +vocifération +éponyme +