使用结构和文件,写一个关于读入读出日期的程序
1、bug显示unknown escape sequence,求大神帮忙指出哪里出错了
2、是不是在函数中改变结构的值,都要用指针结构的写法?
源代码如下
#include<stdio.h>//仍然有Bug
#include<stdlib.h>
int getHolidays(struct Date *);
struct Date
{
int year;
int month;
int day;
};
int main()
{
int i,numHolidays;
struct Date holi[20];
numHolidays=getHolidays(&holi);
printf("The Holiday array contains %d holidays\n",numHolidays);
printf("and contains the elements:\n");
for(i=0;i<numHolidays;i++)
{
printf("%d/%d/%d\n",holi[i].year,holi[i].month,holi[i].day);
}
return 0;
}
int getHolidays(struct Date *holi)
{
char HolidayFile[]="E:\北航生活\大一下\C语言程序设计\作业\Holidays.txt";
struct Date holi[20];
int i=0;
FILE *inFile;
inFile=fopen(HolidayFile,"r");
if(inFile==NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while(fscanf(inFile,"%d/%d/%d",&holi[i]->year,&holi[i]->month,&holi[i]->day)!=EOF)
{
i++;
}
fclose(inFile);
return i;
}
文件holiday 中的信息:
2007/1/1
2007/1/15
2007/2/19
2007/4/6
2007/4/9
2007/5/5
2007/5/21
2007/5/30
2007/7/1
2007/7/4
2007/9/3
2007/10/8
2007/10/9
2007/11/22
2007/12/25
望远
ruibin
相关分类