gpt4 book ai didi

C 程序不打印出值

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

我有一个程序正在查找总数以及链接列表中的中间数字是多少。我的问题是为什么它不打印出值?

代码如下:

int count(list values){
if(values == NULL)
return 0;
else
return 1 + count(values->next);
}

void middle(struct node *head){
int count = 0;
struct node *mid = head;

while (head != NULL){
if(count & 1)
mid = mid->next;

count++;
head = head->next;
}
}

void traverse(list values){
if(values->next)
printf("\n# of the values: %.1f% \nMiddle: %.1f%\n", count, middle);
}

int main(int argc, char *argv[]){
FILE *input = stdin;

list values = readNumbers(input);
traverse(values);
return 0;
}

最佳答案

很难知道从哪里开始。我真的不知道你想做什么。

但是让我们看看这一行:

printf("\n# of the values: %.1f% \nMiddle: %.1f%\n", count, middle);

countmiddle 是函数,但您不会在此处调用这些函数。您只需将这些函数的地址传递给 printf(),而 printf() 并不知道这些是函数。您需要在函数名称后添加括号(count(args)middle(args) 才能调用这些函数。

关于C 程序不打印出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32427141/

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