Random Sentence From A File
--------------------------------------------------------------------------------
Hi;
I wanna write a program which will show a random sentence from a specific file for each execution. Sentence will separated by "\n".
I wrote a code but it isn't work. is there any suggestion.
Please help me...
My Code:
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <conio.h> #include <math.h> void main(void) { char **line,c; int i=0,j=0,*slen,a,k; FILE *myfile; myfile = fopen("mycookies.txt","r"); if (myfile == NULL) { printg("Warning!Cannot open file."); exit -1; } while ( !feof(myfile) ) { fscanf(myfile,"%c",c); while(c!='\n') { line[i][j]=c; fscanf(myfile,"%c",&c); j++; } slen[i]=j; i++ } a=randomize(i); for(k=0;k<slen[i];k++) printf("%c",line[a][k]); getch(); return 0; }



LinkBack URL
About LinkBacks


