gpt4 book ai didi

c - 不兼容的指针错误,会计代码计算器

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:23:17 25 4
gpt4 key购买 nike

我正在尝试创建一个财政代码计算器算法。

代码如下:

    #include<stdio.h>
#include<string.h>

int main()
{
int Day,Month,Year,i;
char Mo;
char Name[1][30];
char Surname[1][30];
char A,B,C,D,E,H,L,M,P,R,S,T;

printf("Insert your birthday day: ");
scanf("%d",&Day);

printf("Insert your birthday month: ");
scanf("%d",&Month);

printf("Insert your birthday year (last two numbers): ");
scanf("%d",&Year);

/*Month calculator*/

switch(Month)
{
case 1:
Mo="A";
break;
case 2:
Mo="B";
break;
case 3:
Mo="C";
break;
case 4:
Mo="D";
break;
case 5:
Mo="E";
break;
case 6:
Mo="H";
break;
case 7:
Mo="L";
break;
case 8:
Mo="M";
break;
case 9:
Mo="P";
break;
case 10:
Mo="R";
break;
case 11:
Mo="S";
break;
case 12:
Mo="T";
break;
}

printf("Your fiscal code is: %d%c%d",Year,Mo,Day);
}

在切换的每种情况下,我都会收到相同的错误:Incompatible pointer to integer conversion assigning to 'char' from 'char[2]'。

错在哪里?

感谢大家!

最佳答案

您正在尝试将 char 分配给 char*Mo 是一个 char 并且用双引号 (") 包围的字符串是以 结尾的 char* >\0. 使用单引号(') 表示字符。

改变

switch(Month)
{
case 1:
Mo="A";
break;
case 2:
Mo="B";
break;
case 3:
Mo="C";
break;
case 4:
Mo="D";
break;
case 5:
Mo="E";
break;
case 6:
Mo="H";
break;
case 7:
Mo="L";
break;
case 8:
Mo="M";
break;
case 9:
Mo="P";
break;
case 10:
Mo="R";
break;
case 11:
Mo="S";
break;
case 12:
Mo="T";
break;
}

switch(Month)
{
case 1:
Mo='A';
break;
case 2:
Mo='B';
break;
case 3:
Mo='C';
break;
case 4:
Mo='D';
break;
case 5:
Mo='E';
break;
case 6:
Mo='H';
break;
case 7:
Mo='L';
break;
case 8:
Mo='M';
break;
case 9:
Mo='P';
break;
case 10:
Mo='R';
break;
case 11:
Mo='S';
break;
case 12:
Mo='T';
//break; Not needed
}

关于c - 不兼容的指针错误,会计代码计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29862793/

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