使用结构和文件,写一个关于读入读出日期的程序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/12007/1/152007/2/192007/4/62007/4/92007/5/52007/5/212007/5/302007/7/12007/7/42007/9/32007/10/82007/10/92007/11/222007/12/25
3 回答
已采纳
望远
TA贡献1017条经验 获得超1032个赞
1.char HolidayFile[]="E:\\北航生活\\大一下\\C语言程序设计\\作业\\Holidays.txt";//注意转义
2.while(fscanf(inFile,"%d/%d/%d",&holi[i].year,&holi[i].month,&holi[i].day)!=EOF)//注意结构体成员操作
3. char HolidayFile[]="E:\\北航生活\\大一下\\C语言程序设计\\作业\\Holidays.txt"; struct Date holi[20];//重复定义holi,函数参数里面传入的就是holi int i=0;
- 3 回答
- 0 关注
- 1833 浏览
添加回答
举报
0/150
提交
取消