Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- void mot(char* m) {
- FILE* f = NULL;
- if((f=fopen("C:\\wordlist.txt", "r")) == NULL) { //erreur d'ouverture
- return;
- }
- srand(time(0));
- fseek(f, 0, SEEK_END);
- int size = ftell(f);
- int pos = rand() % size;
- fseek(f, pos, SEEK_SET);
- int c;
- while((c = fgetc(f)) != '\n' && c!=EOF) {
- fseek(f, -2, SEEK_CUR);
- }
- if(c == EOF) {
- fseek(f,0,SEEK_SET);
- }
- fscanf(f, "%s", m);
- fclose(f);
- }
- int main() {
- char a[200];
- mot(a);
- printf("%s\n", a);
- }
Advertisement
Add Comment
Please, Sign In to add comment