关于函数中的局部变量和静态变量的一个小问题求教

#include

char *getmonth( int n );

int main()
{
int n;
char *s;

scanf("%d", &n);
s = getmonth(n);
if ( s==NULL ) printf("wrong input!\n");
else printf("%s\n", s);

return 0;

}
char getmonth( int n )
{
static char *s /
;这里如果没有static的话,不是应该没有输出吗,但是为什么1,2有输出而其他的没有*/
char ch[13][20] = {"0","January","February","March","April","May","June","July","August","September","October","November","December"};
if(n==1)
return ch[1];
else if(n==2)
return ch[2];
else if(n==3)
return ch[3];
else if(n==4)
return ch[4];
else if(n==5)
return ch[5];
else if(n==6)
return ch[6];
else if(n==7)
return ch[7];
else if(n==8)
return ch[8];
else if(n==9)
return ch[9];
else if(n==10)
return ch[10];
else if(n==11)
return ch[11];
else if(n==12)
return ch[12];
else
return NULL ;

}

static char *s 这个是局部静态变量,他作用域只在char getmonth( int n )中,你在main中定义的s,和函数中的s作用域不同,并没有什么直接联系,另外getmonth返回值应为char*  

你返回的是局部变量,函数一执行完就清空了,应该这么写(实测有效)
#include

char *getmonth( int n );

int main()
{
int n;
//char *s;
static char *s;
scanf("%d", &n);
s = getmonth(n);
if ( s==NULL ) printf("wrong input!\n");
else printf("%s\n", s);

return 0;

}
char* getmonth( int n )
{
static char s ;//这里如果没有static的话,不是应该没有输出吗,但是为什么1,2有输出而其他的没有/
char ch[13][20] = {"0","January","February","March","April","May","June","July","August","September","October","November","December"};
if(n==1)
s = ch[1];
else if(n==2)
s = ch[1];
else if(n==3)
s = ch[3];
else if(n==4)
s = ch[3];
else if(n==5)
s = ch[5];
else if(n==6)
s = ch[6];
else if(n==7)
s = ch[7];
else if(n==8)
s = ch[8];
else if(n==9)
s = ch[9];
else if(n==10)
s = ch[10];
else if(n==11)
s = ch[11];
else if(n==12)
s = ch[12];
return s ;

}