Gudday
Slowly getting my program together. I have various bits that work seprately but having trouble getting them in a coherent whole.
The code below looks for files, in a directory, of form *.RPT. If found any file names are placed in a file called RPT.dat. Then file RPT.dat should be read one line at a time so the each RPT file can be analysed (haven't added this bit yet but it works separately). The program creates the RPT.dat file successful.
The code also checks that RPT.dat exists, if so it continues, if not it leaves.
If RPT.dat exists the program should grab the first line (in fact the only line in my run) and print out a line to say that it has found it.
Instead the program adds 4074(?) NULLS to the RPT.dat file and prints out 4074(?) messages.
Code:
int main (int argc, char *argv[])
{
  FILE *rptFile; /* store any  RPT file names found in here*/
  FILE *inputFile, *errorFile, *indexFile;
  char *CONFIG_FILE = "RPT.dat";
  char fileline[255]; //line in RPT file
  char rptline[25];   //name of RPT file
  struct _finddata_t fileData = {0};
  char rpt_file[8] = "RPT.dat";

  // start a search for all files with an extension of "rpt"
  intptr_t searchHandle = _findfirst("*.rpt", &fileData);
  // if the search started
  if(searchHandle != -1)
  {
       // print a banner
	//puts("Found the following files:");
	do
	{
                // print the file name
		//puts(fileData.name);
		rptFile = fopen (rpt_file, "w+");  /* open data file "rptFile.dat" */
		fprintf(rptFile, "%s\n", fileData.name);  /* write RPT file name to rptFile.dat file  */

	}
        // look for any more files
	while(_findnext(searchHandle, &fileData) == 0);
        // stop the search after all have been enumerated
	_findclose(searchHandle);
  }
  else
  {
       // if we couldn't start a search, print out the reason
	perror("Couldn't enumerate files: ");
  }
  //printf("looking for RPT.dat existence");
   if( (access(CONFIG_FILE, F_OK)) != -1 )
   {
	 printf("An RPT.dat file exists\n");
	 while(fgets(rptline, 25, rptFile)!=NULL) //loop for reading a line up to end of file
      {
		printf("RPT file exists, getting name of it out of file\n");
	  }


   }
   else
   {
	 printf("An RPT.dat file does not exist");
	 return 0;
   }

fclose(rptFile);
return 0;
}
Obviously I have done something absolutely silly but cannot see it.

Please advise.
The RPT.dat is attached (called RPT.txt to get loaded) as is a screen shot of the output.