gpt4 book ai didi

在 C 中调用函数

转载 作者:行者123 更新时间:2023-12-02 05:31:40 24 4
gpt4 key购买 nike

这是我的代码

#include<stdio.h>

orders_char(int c1, int c2, int c3);

void orders_char(int c1, int c2, int c3)
{

if(c1 < c2)
if(c2 < c3)
printf("Ordered characters are: %c %c %c", c1, c2, c3);
else if(c3 < c2 && c1 < c3)
printf("Ordered characters are: %c %c %c", c1, c3, c2);
else if(c2 < c1
if(c1 < c3)
printf("Ordered characters are: %c %c %c", c2, c1, c3);
else if(c3 < c1 && c3 < c2)
printf("Ordered characters are: %c %c %c", c3, c2, c1);
else if(c1 > c3)
if (c3 < c2 && c2 > c1)
printf("Ordered characters are: %c %c %c", c3, c1, c2);
else if(c3 > c2 && c2 < c1)
printf("Ordered characters are: %c %c %c", c2, c3, c1);


return;
}

int main(void)
{

char c1, c2 ,c3;
int i = 65;

printf("Please enter 3 capital letters with no spaces: \n");
scanf("%c%c%c", &c1, &c2, &c3);
orders_char(c1, c2, c3);
return 0;
}

但是我得到了错误:

8.7.c:3: warning: data definition has no type or storage class
8.7.c:6: error: conflicting types for 'orders_char'
8.7.c:3: error: previous declaration of 'orders_char' was here
8.7.c:6: error: conflicting types for 'orders_char'
8.7.c:3: error: previous declaration of 'orders_char' was here
8.7.c: In function `orders_char':
8.7.c:14: error: syntax error before "if"

最佳答案

您确实应该为您的 if 表达式使用 { }。我通过格式化程序运行您的代码,它清楚地表明 ifelse if 没有按照您希望的方式工作。

编辑:

  • 你有很多情况 - 三个变量只有六种可能的排序顺序
  • 您将 int 用于 char,虽然这样做并不不错 - 最好将 char 用于 char。

关于在 C 中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5439895/

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