问答详情
源自:7-2 [Linux C语言] 输入流输出流以及错误流的重定向

求大神,哪里错了?

指针数组怎么不能用了,*pa[]不能用,必须加上个const 这是为什么?

#include<stdio.h>

char *weekname(char *p[], int n); 

int main()

{

const char *week[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

int n;

printf ("Please input a digital:\n");

scanf ("%d", &n);

if (n>=1 && n<=7) printf ("星期%d的英文名是%s", n, weekname(week, n));

else printf ("The digital is invalid\n");

return 0;

 }

char *weekname(char *p[], int n)

 {

  return *(p+n-1);

 }

还有这串代码,自定义函数哪里错了

提问者:qq_愿时光安好_04050009 2017-01-15 12:59

个回答

  • 筑梦之队
    2017-01-15 19:14:36

    我这里是可以运行的。

    #include <stdio.h>

    char* weekname(char *p[], int n); 

    int main()

    {

            char* week[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

            int n;

            printf ("Please input a digital:\n");

            scanf ("%d", &n);

            if (n>=1 && n<=7) {

                    printf ("星期%d的英文名是%s\n", n, weekname(week, n));

            } else{

                     printf ("The digital is invalid\n");

            }


            return 0;

     }


    char* weekname(char *p[], int n)

    {

            return *(p+n-1);

    }