
大神这个c语言实在不会做,才初学3个月,老师布置的任务,有没有样品参考 5
2020-01-10
#include <stdio.h>
#include <time.h>
#define PATH_MENU "menu.txt"
typedef struct {char mday[10];char item[200];float price;}DATA;
int main()
{
time_t t=time(NULL);
struct tm *p2date=localtime(&t);
FILE *fp=fopen(PATH_MENU,"r");
DATA dat[7];
int i;
for(i=0;i<7;++i)
{
fscanf(fp,"%s %s %f",dat[i].mday,dat[i].item,&(dat[i].price));
}
printf("***********************\n");
printf("天天百货,天天惊喜,欢迎惠顾!\n");
printf("今日特价:%s %.2f//斤\n",dat[p2date->tm_wday?p2date->tm_wday-1:6].item,dat[p2date->tm_wday?p2date->tm_wday-1:6].price);
printf(" %s\n",dat[p2date->tm_wday?p2date->tm_wday-1:6].mday);
printf(" %04d.%02d.%02d\n",p2date->tm_year+1900,p2date->tm_mon+1,p2date->tm_mday);
printf("***********************\n");
return 0;
}