因此,我給了塊下面的代碼塊,並告訴他們有三個錯誤。好,那太好了。我要使用「Core」文件和gdb來查看代碼。使用GDB確定代碼錯誤
我不過,我真的很糟糕的理解我所期待的。有人告訴我用命令來運行GDB:
GDB print_test核心
,但我真的不知道以後該怎麼做「核心」的說法呢還是什麼。我對gdb的認識只限於絕對的基礎。任何意見繼續進行,非常感謝。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "natural.h"
/* This program is a test driver for arbitrary precision addition. It expects
* two integers expressed in hex as command-line arguments. Naturals, however,
* are read from streams. Libc has a memory stream. These look like file
* streams, but they actually "read" from the strings. This lets us read two
* natural numbers, add them together, and display the results. There is a
* little bookkeeping at the end to free or release the memory used by the
* natural numbers. These would be destructors or finalizers in C++ or Java.
*/
int main(int argc, char* argv[])
{
natural_t l,r,s;
FILE* fmem;
if (argc != 3) {
fprintf(stderr, "Usage: %s {hexdigits} {hexdigits}\n", argv[0]);
return EXIT_FAILURE;
}
fmem = fmemopen(argv[1], strlen(argv[1]), "r");
l = read_natural(fmem);
fclose(fmem);
fmem = fmemopen(argv[2], strlen(argv[2]), "r");
r = read_natural(fmem);
fclose(fmem);
s = add_naturals(l,r);
print_natural(stdout, s);
printf("\n");
release_natural (&l);
release_natural (&r);
release_natural (&s);
return EXIT_SUCCESS;
}
除了我下面的回答,驅動程序看起來相當健全,所有事情都考慮到了。我會假設你的問題出現在用自然數進行操作的代碼中。 – slugonamission