SuperMonkey

Random

May 10th, 2014
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. void mot(char* m) {
  6.     FILE* f = NULL;
  7.     if((f=fopen("C:\\wordlist.txt", "r")) == NULL) { //erreur d'ouverture
  8.         return;
  9.     }
  10.  
  11.     srand(time(0));
  12.     fseek(f, 0, SEEK_END);
  13.     int size = ftell(f);
  14.     int pos = rand() % size;
  15.     fseek(f, pos, SEEK_SET);
  16.    
  17.     int c;
  18.     while((c = fgetc(f)) != '\n' && c!=EOF) {
  19.         fseek(f, -2, SEEK_CUR);
  20.     }
  21.     if(c == EOF) {
  22.         fseek(f,0,SEEK_SET);
  23.     }
  24.  
  25.     fscanf(f, "%s", m);
  26.  
  27.     fclose(f);
  28. }
  29.  
  30. int main() {
  31.     char a[200];
  32.     mot(a);
  33.  
  34.     printf("%s\n", a);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment