c/c++语言开发共享如何修复用C编写的代码?

它适用于20-20表,但对于其他任何事情它都会崩溃。 该文件位于以下链接: http : //www.csd.uoc.gr/~hy100/glid.txt 。 我无法弄清楚问题是什么,因为当我放一个20-20的表时它起作用,当我给21-20表时,它完全可以完成工作,但在能够返回0之前崩溃; 。

#include  #include  int height, length; char **world, **new_world; int load_world_from_file(char filename[]) { int i, j; char ch; FILE *fp; fp = fopen(filename, "r"); if (fp == NULL ) { perror("Error while opening the file.n"); exit(EXIT_FAILURE); } fscanf(fp, "%d %d", &height, &length); printf("here:%d,%dn", height, length); /*dilosi dunamika tou pinaka kataxoriseis*/ /* declaration under the table entries */ world = (char **) malloc(sizeof(char *) * (height + 1));/*height + 1 ('')*/ for (i = 0; i < 2 * height; i++) { /* height + height ('|') + 1 ('') */ world[i] = (char *) malloc(sizeof(char) * (length + length + 1)); } /* height + 1 ('') */ new_world = (char **) malloc(sizeof(char *) * (height + 1)); for (i = 0; i < 2 * height; i++) { /* height + height ('|') + 1 ('') */ new_world[i] = (char *) malloc(sizeof(char) * (length + length + 1)); } printf("The contents of %s file are :n", filename); i = 0; j = 0; while ((ch = fgetc(fp)) != EOF) { i++; if (i = length + length + 1) { j++; i = 0; } world[j] = ch; printf("%c", world[j]); } printf("n"); for (i = 0; i < (((2 * length) + 2) * height) + 1; i++) { printf("%c", world[i]); } fclose(fp); return 0; } int main() { char filename[30], filename2[30]; printf("Enter the name of file you want to open:n"); scanf("%s", &filename); load_world_from_file(filename); return 0; } 

非常感谢您的帮助。 它

      以上就是c/c++开发分享如何修复用C编写的代码?相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/519577.html

      (0)
      上一篇 2020年12月5日
      下一篇 2020年12月5日

      精彩推荐