File segmentation fault

Hi, I'm new to the board so I apologise if I haven't searched thoroughly enough, but I think this isn't a common topic.

My program is seg faulting when it tries to access a file I've opened:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void prtfl(double dataout[], double absc[], int length)
{
   FILE *redat, *imdat;
   double tmpre[length/2], tmpim[length/2];
   int i;
   char input12[5], mystring[90];

   redat = fopen("myconvre.txt", "w");
   printf("%x\n Eh oh!\n", &redat);
   imdat = fopen("myconvim.txt", "w");

   if((redat==(FILE*)NULL)||(imdat==(FILE*)NULL)) 
   {
      printf("Cannot write to file\n");
      exit(EXIT_FAILURE);
   }

      puts("Kerplaahhh!");
      fputs("Kerplaahhh!", redat);
      puts("Kerplaahhh!");
      printf("Oh, go on!\n");
      fprintf(redat, "Ooh eeh, ooh ahh ahh\n");
      printf("Ooh eeh, ooh ahh ahh\n");



This is my code as it stands at the moment, the program prints the first "Kerplaah" to the screen and the seg faults.

Any ideas why this might be?

My program will, eventually, write an array to the file but to be sure that the seg fault wasn't related to the array I decided to print only strings instead.

I've also tested "fwrite" and even adapting the code to try and read from a file, but that failed. The especially confusing part for me is that another external function used earlier in my program outputs fine, so maybe the problem lies there if no-one can spot anything here.

Cheers!
Okay, done-ish... It turns out that the error was related to my input arrays, but for some reason the program didn't seg fault until it hit the fprintf lines.

Fixed (for now)!
Topic archived. No new replies allowed.