Recently I experienced very strange situation by my C program.
Usually my program works fine, but if I add just a few lines to check elapsed time, the result changes.
The code of which result changed is:
while (!feof(pfInputFile) && (c = fgetc(pfInputFile)) != EOF){
for(i = 1 ; i < SEED_SIZE ; i++){
pcSeq[i-1] = pcSeq[i]; // Shift left all sequence
}
pcSeq[SEED_SIZE - 1] = c;
}
And the code I added and cause a problem is below:
#include <time.h>
time_t start, end;
time(&start); time(&end);
And then, the characters that are read by the above source code are changed to unrecognized character.
Not enough details but I’ll take a wild guess.
You returned a pointer to a local variable
pcSeq. Then in another function you calltime(&start)with the result that thestartvariable now shares the same stack address thatpcSeqhad, so it got overwritten.