请高手用c语言帮忙写个小程序

写一个关于输入数据的小程序
输入n组日期数据(n不确定),一个年月日为一组,以0作为结束标志,输入形式如下

2000 1 1
2004 7 18
2009 10 29
0

#include <stdio.h>
main()
{
struct {int y,m,d;}dat[1000];
int i,j;
for(i=0;1;++i)
{
scanf("%d",&dat[i].y);
if(dat[i].y==0)
break;
scanf("%d%d",&dat[i].m,&dat[i].d);
}
for(j=0;j<i;++j)
printf("%d %d %d\n",dat[j].y,dat[j].m,dat[j].d);
}追问

你这个结构体数组长度只有1000啊
万一输入的数据超过1000怎么办?

追答

这种情况的话,有效的方法呢,是用 动态内存分配+链表 来解决,不过那样会显得比较复杂,我比较偷懒啊,这个地方不想那么麻烦

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-07-17
while(scanf("%d%d%d",&a,&b,&c),a){
//循环体
}
请采纳为最佳答案,谢谢追问

写全一点吧 大哥

第2个回答  2011-07-17
#include <stdio.h>
int main()
{
int year, month, day;
char str[20];
while( gets(str) && str[0] != '0')
{
sscanf(str, "%d %d %d", &year, &month, &day);
}
}追问

你的也是一样啊
结构体数组长度有限啊
我题目中的n是不确定的

相似回答
大家正在搜