编译C语言程序 出错 ....帮忙检查一下吧...
#include<stdio.h><br> #include<math.h><br> #define DaysYear 365<br> #define DaysLeapYear 366<br> <br>void DateTrans(char *chDate ,int *Year,int *nMonth,int *nDay)<br> {<br> int i=0;<br> printf("请输入日期(例如2012/12/22,1992/5):");<br> gets(chDate);<br> while(chDate[i]>=48&&chDate[i]<=57)<br> {<br> *Year+=(chDate[i]-48)*pow(10,3-i);<br> i++;<br> }<br> i++;<br> while(chDate[i]>=48&&chDate[i]<=57)<br> {<br> *nMonth+=(chDate[i]-48)*pow(10,1-i);<br> i++;<br> }<br> i++;<br> <br>if(chDate[9]!='\\0')<br> <br> while(chDate[i]>=48&&chDate[i]<=57)<br> {<br> <br> *nDay+=(chDate[i]-48)*pow(10,1-i);<br> <br> i++;<br> }<br> }<br> int IsLeapYear(int nYear)<br> {<br> if((nYear%100==0&&nYear%400==0)||(nYear%4==0&&nYear%100!=0))<br> return DaysLeapYear;<br> else return DaysYear;<br> }<br> int GetWeekOfFirstday(int nYear)<br> {<br> int i,k=0,days;<br> if(nYear>2000)<br> {<br> i=nYear-2000;<br> for(;k<i;k++)<br> days+=IsLeapYear(2000+k);<br> }<br> else if(nYear==2000) return 1;<br> else<br> {<br> i=2000-nYear+1;<br> for(k=1;k<=i;k++)<br> days+=IsLeapYear(2000-k);<br> }<br> return days%7;<br> }<br> int GetWeek(int nYear,int nMonth,int nDay,int nWeekOfFirstday)<br> {<br> int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};<br> int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};<br> int days,i,weekOfDay;<br> weekOfDay=GetWeekOfFirstday(int nYear);<br> if(IsLeapYear(nYear)==365)<br> {<br> for(i=1;i<nMonth;i++)<br> days+=nDaysYear[i-1];<br> return (weekOfDay+days+nDay)%7;<br> }<br> else<br> {<br> for(i=1;i<nMonth;i++)<br> days+=nDaysLeapYear[i-1];<br> return (weekOfDay+days+nDay)%7;<br> }<br> }<br> void PrintCalendar(int nYear,int nMonth,int nDay,char *chDate)<br> {<br> int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};<br> int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};<br> int weekOfDay,days,i;<br> weekOfDay=GetWeekOfFirstday(nYear);<br> for(i=1;i<nMonth;i++)<br> days+=nDaysYear[i-1];<br> weekOfDay=(weekOfDay+days)%7;<br> if(chDate[9]=='\\0')<br> {<br> <br> printf("*********************************\<br>");<br> <br> printf("SUN MON TUE WEN THU FRI STA\<br>");<br> <br> for(i=0;i<weekOfDay;i++)<br> <br> printf("<br> ");<br> <br> if(IsLeapYear(nYear)==365)<br> {<br> <br> for(int k=1;k<nDaysYear[nMonth-1];k++)<br> {<br> <br> printf("%3d ",k);<br> <br> if(i%6==0)<br> <br> printf("\<br>");<br> }<br> }<br> <br> else<br> {<br> <br> for(int k=1;k<nDaysLeapYear[nMonth-1];k++)<br> {<br> <br> printf("%3d ",k);<br> <br> if(i%6==0)<br> <br> printf("\<br>");<br> }<br> }<br> <br> printf("*********************************\<br>");<br> else<br> {<br> printf("This day(%s) is ")<br> switch(GetWeek(nYear,nMonth,nDay))<br> {<br> case 0:printf("Sunday.");<br> case 1:printf("Monday.");<br> case 2:printf("Tuesday.");<br> case 3:printf("Wednesday.");<br> case 4:printf("Thursday.");<br> case 5:printf("Friday.");<br> case 6:printf("Saturday.");<br> }<br> }<br> }<br> void main()<br> {<br> DateTrans();<br> PrintCalendar(*Year,*nMonth,*nDay);<br> }
答案:/*只是能够编译通过了, 好多问题*/<br> <br>#include<stdio.h><br> #include<math.h><br> #define DaysYear 365<br> #define DaysLeapYear 366<br> <br>void DateTrans(char *chDate ,int *Year,int *nMonth,int *nDay)<br> {<br> int i=0;<br> printf("请输入日期(例如2012/12/22,1992/5):");<br> gets(chDate);<br> while(chDate[i]>=48&&chDate[i]<=57)<br> {<br> *Year+=(chDate[i]-48)*pow(10,3-i);<br> i++;<br> }<br> i++;<br> while(chDate[i]>=48&&chDate[i]<=57)<br> {<br> *nMonth+=(chDate[i]-48)*pow(10,1-i);<br> i++;<br> }<br> i++;<br> <br>if(chDate[9]!='\\0')<br> <br> while(chDate[i]>=48&&chDate[i]<=57)<br> {<br> <br> *nDay+=(chDate[i]-48)*pow(10,1-i);<br> <br> i++;<br> }<br> }<br> int IsLeapYear(int nYear)<br> {<br> if((nYear%100==0&&nYear%400==0)||(nYear%4==0&&nYear%100!=0))<br> return DaysLeapYear;<br> else return DaysYear;<br> }<br> int GetWeekOfFirstday(int nYear)<br> {<br> int i,k=0,days;<br> if(nYear>2000)<br> {<br> i=nYear-2000;<br> for(;k<i;k++)<br> days+=IsLeapYear(2000+k);<br> }<br> else if(nYear==2000) return 1;<br> else<br> {<br> i=2000-nYear+1;<br> for(k=1;k<=i;k++)<br> days+=IsLeapYear(2000-k);<br> }<br> return days%7;<br> }<br> int GetWeek(int nYear,int nMonth,int nDay) //去掉最后一个参数<br> {<br> int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};<br> int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};<br> int days,i,weekOfDay;<br> weekOfDay = GetWeekOfFirstday(nYear); //实参不用加类型<br> if(IsLeapYear(nYear)==365)<br> {<br> for(i=1;i<nMonth;i++)<br> days+=nDaysYear[i-1];<br> return (weekOfDay+days+nDay)%7;<br> }<br> else<br> {<br> for(i=1;i<nMonth;i++)<br> days+=nDaysLeapYear[i-1];<br> return (weekOfDay+days+nDay)%7;<br> }<br> }<br> void PrintCalendar(int nYear,int nMonth,int nDay,char *chDate)<br> {<br> int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};<br> int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};<br> int weekOfDay,days,i;<br> weekOfDay=GetWeekOfFirstday(nYear);<br> for(i=1;i<nMonth;i++)<br> days+=nDaysYear[i-1];<br> weekOfDay=(weekOfDay+days)%7;<br> if(chDate[9]=='\\0')<br> {<br> <br> printf("*********************************\<br>");<br> <br> printf("SUN MON TUE WEN THU FRI STA\<br>");<br> <br> for(i=0;i<weekOfDay;i++)<br> <br> printf("<br> ");<br> <br> if(IsLeapYear(nYear)==365)<br> {<br> <br> for(int k=1;k<nDaysYear[nMonth-1];k++)<br> {<br> <br> printf("%3d ",k);<br> <br> if(i%6==0)<br> <br> printf("\<br>");<br> }<br> }<br> <br> else<br> {<br> <br> for(int k=1;k<nDaysLeapYear[nMonth-1];k++)<br> {<br> <br> printf("%3d ",k);<br> <br> if(i%6==0)<br> <br> printf("\<br>");<br> }<br> }<br> <br> printf("*********************************\<br>");<br> } //少个}<br> else<br> {<br> printf("This day(%s) is "); //少个;<br> switch(GetWeek(nYear,nMonth,nDay))<br> {<br> case 0:printf("Sunday.");<br> case 1:printf("Monday.");<br> case 2:printf("Tuesday.");<br> case 3:printf("Wednesday.");<br> case 4:printf("Thursday.");<br> case 5:printf("Friday.");<br> case 6:printf("Saturday.");<br> }<br> }<br> }<br> void main()<br> {<br> char chDate;<br> int Year;<br> int nMonth;<br> int nDay;<br> DateTrans(&chDate ,&Year,&nMonth,&nDay);//这样改<br> PrintCalendar(Year,nMonth,nDay,&chDate);<br> }
上一个:关于C语言课题设计(学生信息管理系统)
下一个:求位C语言编程高手帮忙编程序?