You should probably avoid pointers for anything except little test programs until you know how they work. The problem can be easily solved with an array to hold one line and two passes through the file:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ( void )
{
FILE *fp = fopen ( "mycookies.txt", "r" );
if ( fp != NULL ) {
char line[BUFSIZ];
int nlines = 0, r;
srand ( (unsigned)time ( NULL ) );
/* Count the lines in file */
while ( fgets ( line, sizeof line, fp ) != NULL )
++nlines;
/* Restart file & get random line # */
rewind ( fp );
r = rand() % nlines;
/* Find line #r */
while ( fgets ( line, sizeof line, fp ) != NULL ) {
if ( r-- <= 0 )
break;
}
printf ( "Random line:\n%s", line );
}
return 0;
}
As a few people already said, you have a bunch of syntax errors in your code.