标题:细节问题
只看楼主
不负年华
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-6-28
结帖率:66.67%
已结贴  问题点数:20 回复次数:2 
细节问题
这是我的程序#include "stdio.h"
void main()
{int number; char today[20];
    printf("please put the number:");
     scanf("%d",&number);
     switch(number)
     {case  1: today="monday";break;
      case  2: today="tuseday";break;
      case  3: today= "wendnesday";break;
      case  4: today="thursday";break;
      case  5: today="friday";break;
      case  6: today="saturday";break;
      case  7: today="sunday";break;
      default: today="no this day";};
     printf("%s",today);
   
}显示有错误

这是别人帮我改的#include "stdio.h"
void main()
{int number; char today[20],*p=today;
     printf("please put the number:");
      scanf("%d",&number);
      switch(number)
      {case   1:p="monday";break;
       case   2:p="tuseday";break;
       case   3:p="wendnesday";break;
       case   4:p="thursday";break;
       case   5:p="friday";break;
       case   6:p="saturday";break;
       case   7:p="sunday";break;
       default:p="no this day";};
       printf("%s\n",p);
     
}是正确的 额 我想问 为什么需要*p=taday 这一步 为什么这里的p不能直接用today代替
搜索更多相关主题的帖子: 细节 
2010-07-28 17:13
BJ_BOY
Rank: 4
等 级:业余侠客
威 望:1
帖 子:77
专家分:225
注 册:2010-2-4
得分:10 

以下代码在Dev C++中调试通过!何必用*p呢?

程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{    

      int number;

      char today[20];
      printf("please put the number:");
      scanf("%d",&number);
      switch(number)
      {case 1:
              strcpy(today,"monday");
              break;
       case 2:
              strcpy(today,"tuseday");
              break;
       case 3:
              strcpy(today,"wendnesday");
              break;
       case 4:
              strcpy(today,"thursday");
              break;
       case 5:
              strcpy(today,"friday");
              break;
       case 6:
              strcpy(today,"saturday");
              break;
       case 7:
              strcpy(today,"sunday");
              break;
       default:
              strcpy(today,"no this day");
       };
      

       printf("%s\n",today);
      

       system("PAUSE");
       return 0;
}

2010-07-28 17:24
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
得分:10 
数组与指针的关系,回去看书吧

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2010-07-28 17:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-314195-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.126186 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved