6-1 输出月份英文名
代码
char *getmonth( int n )
{
char *month[13] = {"January","February","March","April","May","June","July","August","September","October","November","December","wrong input!"};
char *s;
if(n>=1 && n<=12)
{
s = month[n-1];
}else
{
s = month[12];
}
return s;
}
6-2 查找星期
代码
int getindex( char *s )
{
char *day[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int i=0;
for(i=0; i<7; i++)
{
if( strcmp(s,day[i]) == 0 )
return i;
}
return -1;
}
6-3 计算最长的字符串长度
代码
int max_len( char *s[], int n ){
int i,count=0,j,q[20]={0};
for(i=0;i<n;i++){
for(j=0;*(*(s+i)+j)!='\0';j++){
}
q[i]=j;
}
count=q[0];
for(i=0;i<n;i++){
if(q[i]>count){
count=q[i];
}
}
return count;
}