gpt4 book ai didi

c - 尝试使用循环读取 n 个图像时出错?

转载 作者:行者123 更新时间:2023-11-30 20:28:02 24 4
gpt4 key购买 nike

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 张图像。如何解决这个问题?

最佳答案

尚未为filenameframe_id分配内存。在存储字符串之前使用 malloc 分配内存或calloc 。或者只是将它们声明为静态数组。

char filename[256]="";
char frame_id[256] = "";

关于c - 尝试使用循环读取 n 个图像时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14543385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com