这个段错误是什么原因,看了好久没发现
#include<stdio.h>#include<string.h>
#include<time.h>
typedef struct
{
int y;
int m;
int d;
int h;
int min;
}date;
date *cur_time()
{
time_t t;
date *p;
struct tm *pt ;
char *pc ;
char *pm[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int n=0,m=0;
char month[5],day[4],hour[4],min[4],year[6];
char str[50];
time(&t);
pc=ctime(&t);
printf("ctime:%s", pc);
for(;*pc != '\0';pc++,n++)
{
str[n] = *pc;
}
str[n] = '\0';
pc = str;
if(*(pc+3) = ' ' && *(pc+7) == ' ')
for(n=4;n<7;n++)
{
month[n-4] = *(pc+n);
}
month[3] = '\0';
pc = pc+7;
for(n=1;n<3;n++)
{
day[n-1] = *(pc + n);
}
day[2] = '\0';
if(day[0] != ' ')
(*p).d = (day[0]-'0')*10+(day[1]-'0');
else
(*p).d = (day[1]-'0'); //调试显示是此行出现段错误
pc = pc+3;
for(n=1;n<9;n++)
{
if(n>=1 && n<3)
hour[n-1] = *(pc + n);
if(n>=4 && n<6)
min[n-4] = *(pc + n);
}
hour[2]='\0';
min[2]='\0';
(*p).h = (hour[0]-'0')*10+(hour[1]-'0');
(*p).min = (min[0]-'0')*10+(min[1]-'0');
pc=pc+10;
for(n=0;n<=3;n++)
{
year[n] = *(pc+n);
}
year[4] = '\0';
(*p).y = (year[0]-'0')*1000+(year[1]-'0')*100+(year[2]-'0')*10+(year[3]-'0');
for(n=0;n<12;n++)
{
if(strcmp(month,pm[n]) == 0)
{
(*p).m = n+1;
break;
}
}
return p;
}
int main()
{
date *x;
x = cur_time();
printf("%d %d %d %d %d\n",(*x).y,(*x).m,(*x).d,(*x).h,(*x).min);
return 0;
}
各位大神帮帮忙,是什么原因造成的段错误呢?要怎么改呢?