Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #define MAX_SIZE 50
- int main(void)
- {
- char fileName[] = "compliments.txt";
- char test= 0;
- int currChar = 'a';
- FILE * compliments = fopen(fileName, "r");
- long int characters;
- if(compliments == NULL)
- {
- fprintf(stderr,"Could not open file, exiting\n");
- return 1;
- }
- srand(time(NULL));
- fseek(compliments,0,SEEK_END);
- characters = ftell(compliments);
- rewind(compliments);
- characters = rand() % characters;
- fseek(compliments,characters,SEEK_SET);
- while (test != '\n' && !fseek(compliments,-2,SEEK_CUR)) test = fgetc(compliments);
- if (ftell(compliments) < 3) rewind(compliments);
- for(currChar = fgetc(compliments);currChar!= '\n' && !feof(compliments);currChar = fgetc(compliments)) printf("%c", (char)currChar);
- printf("\n");
- fclose(compliments);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement