Sweetbear.
2021-10-14 22:42
采纳率: 83.3%
浏览 22

哪里的问题呀求解求解

显示error c2015:too many characters in constant怎么回事
#include<stdio.h>
main()
{
int a;
float w;
printf("请输入一个整数:");
scanf("%d",&a);
switch(a<=6)
{
case 0:w='Sunday';break;
case 1: w='Monday';break;
case 2:w='Tuesday';break;
case 3:w='wednesday';break;
case 4:w='Tursday';break;
case 5:w='Friday';break;
case 6:w='Saturday';break;
default :w='None';
}
printf("w=%c\n",w);
}

  • 收藏

2条回答 默认 最新

  • 上下求索. 2021-10-14 22:55
    已采纳
    1. w 类型float不能存放字符串
    2. ''表示单个字符,不能表示字符串
    3. 单个字符可以=赋值,字符串不可以
      main()
      {
       int a;
       char w[32] = {0};       //float w;
       printf("请输入一个整数:");
       scanf("%d",&a);
       switch(a<=6)
       {
           case 0:strcpy (w, "Sunday");break;
           case 1:strcpy (w, "Monday");break;
           case 2:strcpy (w, "Tuesday");break;
           case 3:strcpy (w, "wednesday");break;
           case 4:strcpy (w, "Tursday");break;
           case 5:strcpy (w, "Friday");break;
           case 6:strcpy (w, "Saturday");break;
           default :strcpy (w, "None");
       }
       printf("w=%s\n",w);
      }
      
    已采纳该答案
    打赏 评论
  • 
    #include<stdio.h>
    int main()
    {
    int a;
    printf("请输入一个整数:");
    scanf("%d",&a);
    switch(a)
    {
    case 0:printf("Sunday");break;
    case 1:printf("Monday");break;
    case 2:printf("Tuesday");break;
    case 3:printf("wednesday");break;
    case 4:printf("Tursday");break;
    case 5:printf("Friday");break;
    case 6:printf("Saturday");break;
    default :printf("None");
    }
    
    }
    

    img

    打赏 评论

相关推荐 更多相似问题