Advertisement
plaguenurse

cygnetII-scrubsearch.c

Oct 23rd, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #define MAX_SIZE 50
  6. int main(void)
  7. {
  8.     char fileName[] = "compliments.txt";
  9.     char test= 0;
  10.     int currChar = 'a';
  11.     FILE * compliments = fopen(fileName, "r");
  12.     long int characters;
  13.     if(compliments == NULL)
  14.     {
  15.         fprintf(stderr,"Could not open file, exiting\n");
  16.         return 1;
  17.     }
  18.     srand(time(NULL));
  19.     fseek(compliments,0,SEEK_END);
  20.     characters = ftell(compliments);
  21.     rewind(compliments);
  22.     characters = rand() % characters;
  23.     fseek(compliments,characters,SEEK_SET);
  24.     while (test != '\n' && !fseek(compliments,-2,SEEK_CUR)) test = fgetc(compliments);
  25.     if (ftell(compliments) < 3) rewind(compliments);
  26.     for(currChar = fgetc(compliments);currChar!= '\n' && !feof(compliments);currChar = fgetc(compliments)) printf("%c", (char)currChar);
  27.     printf("\n");
  28.     fclose(compliments);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement