문제

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 call time(&start) with the result that the start variable now shares the same stack address that pcSeq had, so it got overwritten.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top