-2
void main() {
int frame_number = 0;
do {
    char *filename = "";
    strcpy(filename, "frame_");
    char *frame_id = "";
    itoa(frame_number, frame_id, 10);
    strcat(filename, frame_id);
    strcat(filename, ".bmp");

    FILE* f  = fopen(filename, "rb");
    if (!f) {
        printf("Could not read!");
        system("Pause");
    }
    else
        printf("Read!");
    fclose(f);
    frame_number++;
} while (frame_number < 20);
}

每当我运行它时,我都会收到错误access violation writing location!!!文件夹中有大约 40 张图像。如何解决这个问题?

4

1 回答 1

1

没有为filename和分配内存frame_id在使用malloccalloc存储字符串之前分配内存。或者只是将它们声明为静态数组。

char filename[256]="";
char frame_id[256] = "";
于 2013-01-27T01:06:00.077 回答