I am working on Ubuntu 12.04 with Code::Blocks and the GNU GCC Compiler.
The program (or part thereof) that I am writing is supposed to read in data from a group of textfiles in a folder on my computer. The code below seems to work (or at least works at first sight, since now I get no errors.) But the problem is that my debugger does not stop at any breakpoints I place within the for loop.
(The code itself should be fairly simple to understand)
#include "data.h"
int importAllData(){
for(int i = 1; i <= NUMBERFILES; i++){
char filename[300];
FILE *fp;
int noActivities, noResources, n;
char number[10];
sprintf(number, "%d", i); //writes the number into the array with a decimal integer formatting
strcpy(filename, "/home/louisphilippe/Dropbox/4_Programming/2_Cpp/NPVassignment/NPVassignment/NPVdata/Pat");
strcat(filename, number); //Appends the number string to the filename string
strcat(filename, ".rcp"); //Appends the file extension
fp = fopen(filename, "r");
if(fp == NULL){
return 101; //import data error 101 --> filepointer points to invalid adress
}//end valid filepointer check
fscanf(fp, "%d%d", &noActivities, &noResources); //Read in the number of resources
if(noActivities > MAX_ACTIVITIES || noResources > MAX_DIFFERENT_RESOURCES) return 102;
}//end file loop
return 0;
}//end import all data method
I have searched but found no explanation for this. The only thing I can note out of the ordinary is that I was unable to specify a relative file path to the files, hence the absolute file path in the code above. (I am not used to working with I/O in c++).
If I place statements outside the for loop or make another loop the compiler stops at breakpoints perfectly.
This is probably something really simple that I am missing but I have been trying to figure it out the past two hours but I just can't seem to find why.
What lines did you set the breakpoints on?
Have you verified that the function doesn't exit during the first iteration?
Have you verified that the loop is entered at all (more specifically, what is the value of NUMBERFILES)?
I have set the breakpoints on virtually any line of the loop, but none of them seem to work.
The function does go through the loops, I have already tested this with a simple output written to the terminal, the data read also seems to be correct when I write it to the terminal.
NUMBERFILES is a constant and has a value of 900, the exact number of files in the folder.
Another thing worth noting is that whenever I place a breakpoint within the loop the compiler stops not at the breakpoint but at this line:
sprintf(number, "%d", i); //writes the number into the array with a decimal integer formatting