I am trying to store all of the tokens in an array. But after it store racecar in the array i get an access violation,Unhandled exception at 0x6515f8e0 (msvcr90d.dll) in Assignment2.exe: 0xC0000005: Access violation reading location 0x00000000.
Here is the file im reading from:
Bob went to town in a racecar.
Hannah plays with her mom outside.
Jill likes to play battleship with a radar.
Dad had his life saved by a reviver.
The rotator makes a helicopter blade spin.
We went down the river in a kayak.
My new car is a honda civic.
Nan took a peep at the rotor and he made a toot.
and here is my code
char displayFile(char txt[])
{
char filename[100];
char *toks;
int i=0;
int j=0;
char strArr[100][100];
FILE *rfPtr;
FILE *cfPtr;
printf("Please enter a file to read for palindromes.\n");
scanf("%s",filename);
rfPtr=fopen(filename,"r");
cfPtr=fopen("d:\\output.txt","w");
if (rfPtr==NULL||cfPtr==NULL)
{
printf("File cannot be opened!\n");
}
else
{
//while(!feof(rfPtr)){
while(fgets(txt,200,rfPtr)!=NULL){
toks=strtok(txt," .\n");
while(toks!=NULL){
fprintf(cfPtr,"%s\n",toks);
toks=strtok(NULL," .\n");
sscanf(toks, "%s", strArr[i]);
i++;
}
}
for(j=0;j<i;j++){
printf("%s",strArr[j]);
}
}
fclose(rfPtr);
fclose(cfPtr);
return txt;
}
Any help would be appreciated!