gpt4 book ai didi

c - 将数字打印成文字。我已经写了这个程序。但我遇到了段错误

转载 作者:行者123 更新时间:2023-11-30 18:55:36 25 4
gpt4 key购买 nike

这段代码给出了段错误,请帮助我找到错误。

#include<stdio.h>

void main()
{
char *single_numbers[10] =
{
"","one","two","three","four","five"
,"six","seven","eight","nine"
};
char *tens_numbers[8] =
{
"twenty","thirty","fourty","fifty"
,"sixty","seventy","eighty","ninety"
};
char *teens[9] =
{
"eleven","twelve","thirteen","fourteen"
,"fifteen","sixteen","seventeen"
,"ëighteen","nineteen"
};
int number,thousands,hundreds,tens,units,temp;
printf("enter the number");
scanf("%d",&number);
thousands=number/1000;
hundreds=(number%1000)/100;
temp=(number%100);
tens=temp/10;
units=number%10;
if(temp>=20)
printf("%sthousand %shundred %s%s"
,*single_numbers[thousands]
,*single_numbers[hundreds]
,*tens_numbers[tens - 2]
,*single_numbers[units]);
else
printf("%sthousand %shundred %s"
,*single_numbers[thousands]
,*single_numbers[hundreds]
,*teens[temp - 10]);
}

最佳答案

不要取消引用single_numbers[thousands]等等。这些已经是 char*,如果您取消引用它们,则会将它们设为 char,但 printf 需要 char*,因此它遵循给定的char,这会导致段错误。

关于c - 将数字打印成文字。我已经写了这个程序。但我遇到了段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27359836/

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