Gudday all
I am a little puzzled by the NULL or \0 that terminates strings and how is it generated and tested for.
I am reading in a list of file names as the contents of a file (file A) . I then wish to open File A and use it's contents to open the text files in question and analyse them.
The problem I have is that I can open file A ok and print out its contents but I can't seem to open the individual files and print their contents.
I am want to read out their contents line by line and print them for a start. I am using a NULL check to get the whole line but it seems to be ignored
Code:
while (fgets(fileline, 22, tmpFile)!=NULL) {
printf("*** Inside the RPT file contents ***\n");
The generation of File A is
Code:
intptr_t searchHandle = _findfirst("*.rpt", &fileData);
// if the search started
if (searchHandle != -1) {
// print a banner
//puts("Found the following files:");
rptFile = fopen (rpt_file, "w+"); /* open data file "rptFile.dat" for writing */
do {
// print the file name
//puts(fileData.name);
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);
fclose(rptFile);
The contents of file A have the form 20090220085501237.RPT which is 21 characters. I have allowed 22 characters for the fgets to have the \0 included. Is the \0 automatically included when the line is added to File A? Do I have to included it separately? Is NULL the best check?
The opening of file A is
Code:
if ( (access(rpt_file, F_OK)) != -1 ) {
//printf("An RPT.dat file exists\n");
rptFile = fopen (rpt_file, "r");
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");
printf("%s", rptline); //print the name of each RPT file found
printf(" Opening %s", rptline);
//open each RPT individually and print out it's contents.
tmpFile = fopen(rptline, "r"); /* open data file "rptFile.dat" for reading */
while (fgets(fileline, 22, tmpFile)!=NULL) {
printf("*** Inside the RPT file contents ***\n");
}
printf(" Closing %s", rptline);
fclose(tmpFile);
}
} else {
printf("An RPT.dat file does not exist");
return 0;
}
(I do hope my request is clear enough)