gpt4 book ai didi

c - 如何在C程序中返回一个char函数?

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

我不知道如何存储返回字符函数,以便我可以将其返回以在主函数中使用,

char process_3 (int step_2)
{
if (step_2 % 2 == 0)
{
printf ("A");
}
else if (step_2 % 3 == 0)
{
printf ("F");
}
if (step_2 % 5 == 0)
{
printf ("K");
}
else if (step_2 % 7 == 0)
{
printf ("P");
}
if (step_2 % 11 == 0 || step_2 % 13 == 0)
{
printf ("T");
}
else
{
printf ("Z");
}
return process_3;
}

最佳答案

试试这个:

char process_3 (int step_2)
{
char c;
if (step_2 % 2 == 0)
{
c = 'A';
}
else if (step_2 % 3 == 0)
{
c = 'F';
}
if (step_2 % 5 == 0)
{
c = 'K';
}
else if (step_2 % 7 == 0)
{
c = 'P';
}
if (step_2 % 11 == 0 || step_2 % 13 == 0)
{
c = 'T';
}
else
{
c = 'Z';
}
return c;
}

您可以使用单引号将字符分配给变量,也可以从函数中返回它们。

关于c - 如何在C程序中返回一个char函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7440065/

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