Tag: c

C – 对这种奇怪的行为感到茫然

所以…我有一小段代码,我早上大部分时间都在做。 这只是一个小项目,可以帮助我记住语法等等。 我显然错过了某种大错误,因为代码因为我不理解的原因返回了分段错误。 #include #include #include #include #include struct cards { int card_value[99]; char card_name[99]; char card_suit[99]; int card_tally; }; struct cards hand[2]; void tally (int a) { int k, j; for (k=0; k5; d++) { if (hand[a].card_name[d] ==’A’) { int y; int z = 10; for (y=0; y<5; y++) z = z + hand[a].card_value[y]; […]

用strtok分割故障

#include #include int main(){ char path[] = “/fs/lost+found”; char* temp; temp = strtok(path,”lost+found”); while(temp != NULL){ printf(“\n %s \n”,temp); temp = strtok(path,”lost+found”); } return 0; } 我想提取丢失+找到的字符串。 上面的程序进入无限循环并打印分隔符“lost + found”之前的“/” [root @ rs]#。/ a.out分段错误

如何计算文件中的数字?

这是错误的。 我的代码出了什么问题? #include “stdafx.h” #include “stdlib.h” #include “ctype.h” int _tmain(int argc, _TCHAR* argv[]) { FILE* input; int num; int numCount = 0; input = fopen(“123.txt”, “r”); if (!input) { printf(“No file \a\n”); exit (101); } while ((fscanf(input, “%d”, &num)) == 1) printf(“%d”, num); if (isdigit(input)) numCount++; printf(“number count: %d”, numCount); return 0; }

printf与scanf请求输入。 BST循环错误

我一直试图看看为什么printf在打印文件输入后没有打破循环。 .c文件是BST,我现在正在测试是否已经构建了一个树,但似乎无法退出printf循环。 我需要printf循环来获得代码的正确输出。 有关此错误发生原因的任何建议。 显示完整的代码和输出。 #include “bst.h” #include #include ///Author: Joe W //arbitrary list of temp nodes TreeNode *new_node, *root, *tmp, *parent; int elemArray[100], i1, i2, i0; /* Insert a new node into the tree by referencing the root and using recursion */ TreeNode* getN(int dataElem) { TreeNode* temp; temp = malloc(sizeof(TreeNode*)); temp-> left = […]

如何将c代码移植到java中? 开始说明

我正在努力将库从C ++移植到Java。 我想知道开始这个端口的第一个/初始步骤。 我不确定如何测试/调试? 我可以从“主”文件开始并开始重写代码,但是我如何以及何时测试我在做什么? 当我完成COMPLETE端口? 我该如何开始,任何帮助都会很棒。 任何跨平台/ etc编译器都会有帮助吗? 请告诉我相应的步骤

带有指向下一个结构的指针?

我想要一个会话,我在链接列表中的size变量中插入了10个不同的整数。 我相信我应该使用result_register()吗? 当存储所有10个整数时,我想通过输入result-> size打印出来。 我是链接列表的新手,所以请保持温和。 struct result { int size; }; struct result* result_next() { // What do I type here? } void result_register(int size) { // What do I type here? } 主要 struct result* result; while ((result = result_next())) printf(“%d\n”, result->size); 然后我希望能够通过如上所述打印出结果。

%dn是格式字符串吗?

我最近在代码中遇到了这一行 – fprintf(logfile,” |-IP Version : %dn”,(unsigned int)iph->version); 这里的“%dn”是格式字符串吗? 如果是这样,它意味着什么?

如何在Turbo C IDE中查看程序的输出?

如何在C中打印#include #include #include void main() { printf(“#include”); } 如何获得输出 #include 你必须把getch(); 然后按Ctrl + f9而不是alt + f5

如何在一个分配C中动态分配2D数组

你能帮我弄清楚如何在一次分配呼叫中分配2Darrays吗? 我试着做: int ** arr =(int **)malloc(num * num * sizeof(int *)); 但它不起作用。 num是行和列。

打印后出现奇怪的分段错误

写了一个简单的交换程序,效果很好; 但是在打印完所有内容后会出现分段错误 。 #include void swap(int* p1,int* p2){ int* temp; *temp = *p1; *p1 = *p2; *p2 = *temp; } int main(){ int a,b; a = 9; b = 8; printf(“%d %d \n”,a,b); swap(&a,&b); printf(“%d %d \n”,a,b); return 0; } 输出: 9 8 8 9 Segmentation fault 我应该简单地忽略这一点并继续前进或者是否有一些非常奇怪的事情发生?