| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:写了一个程序,可以编译,但无法运行,求指教,谢谢,急
只看楼主 加入收藏
ijnbhu8
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-4-24
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:4 
写了一个程序,可以编译,但无法运行,求指教,谢谢,急
一个程序,从年月日得出一年第几天,在用别的方程换算回年月日,输出到txt
#include <stdio.h>
#include <stdlib.h>
#define MAX_ELEMS 100

int calDayofyear (int month, int year, int day,int *daysofmonthArray);
bool isLeapyear (int year);
int getData (FILE *spIn,int *daysofmonthArray);
int writeData (FILE *spOut, int *daysArray,int *yearsArray, int *dayofmonthArray,int numElems);
void caclCalendar(int *daysArray, int *yearsArray, int *dayofmonthArray,int k);

int main (void)
{
    int daysofmonthArray[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int numElems;  
    int daysArray[MAX_ELEMS];
    int yearsArray[MAX_ELEMS];
   
   
    FILE *spOut;
    FILE *spIn;
   
    getData (spIn, daysofmonthArray);
    writeData ( spOut,  daysArray, yearsArray, daysofmonthArray,  numElems);
   
 
system("pause");
return 0;
}


int getData (FILE *spIn,int *daysofmonthArray)
{
    int ioResult,month,day,year,numElems;
    int daysArray[MAX_ELEMS];
    int yearsArray[MAX_ELEMS];
   
    if(!(spIn = fopen("Lab1Input.txt","r"))){
              printf("\aError opening input file\n");
              return 0;
              }
   
    for (int i=0; i<MAX_ELEMS; ++i)
    {
        ioResult=fscanf(spIn, "%d%d%d", month, day, year);
        if (ioResult==EOF)
             return 0;
        else
             {if((month<=12 || month>=1 )&& (year<=9999 || year>=1000))
                  yearsArray[i]=year;
             calDayofyear ( month,  year, day,  daysofmonthArray);
                  daysArray[i]=day;
                  }
        return numElems=i++;
    if(fclose(spIn)==EOF){
        printf("\aError closing input file\n");
        exit (101);
        }
}}
            

int calDayofyear (int month, int year, int day,int *daysofmonthArray)
{
    int daysArray=0;
   
    if((month<=12 || month>=1 )&& (year<=9999 || year>=1000))
        {
      
       if(daysofmonthArray[month]<day||day<=0)
            return 0;
       else {
       for(int i=1;i<month;i++)
       {
       daysArray=daysArray+daysofmonthArray[i];
       }
       daysArray=daysArray+day;
       if (isLeapyear(year)==true)
       return daysArray++;
       else
       return daysArray;
       }}
    else
        return -1;
}


bool isLeapyear (int year)
{        
     
     if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
          return true;
     else
          return false;
     
}

int writeData (FILE *spOut, int *daysArray,int *yearsArray, int *dayofmonthArray, int numElems)
{
     int *pday, *pmonth;
   
     if(!(spOut = fopen("Lab1Output.txt","r"))){
              printf("\aError opening output file\n");
              return 0;
              }
     
     fprintf(spOut, "Day of Year     Calendar Date");
     
     for (int i=0; i<numElems; ++i){
         fprintf(spOut,"    %d", daysArray[i]);
         caclCalendar(daysArray,yearsArray,dayofmonthArray,i);
         fprintf(spOut,"                %d/%d/%d", *pday, *pmonth, yearsArray[i]);
         }
         
     if(fclose(spOut)==EOF){
        printf("\aError closing input file\n");
        exit (201);
        }
     
         
}
         
void caclCalendar(int *daysArray, int *yearsArray, int *dayofmonthArray,int k)
{
     int i=0;
     int *pday, *pmonth;
     if (isLeapyear (yearsArray[k])==true)
          dayofmonthArray[2]=29;
         
     do{
          *pday = daysArray[k]-dayofmonthArray[i];
          i++;}
     while(daysArray[k]-dayofmonthArray[i]>0);

     *pmonth=i;

return;
}
         
     
搜索更多相关主题的帖子: 编译 指教 运行 
2010-04-24 04:45
ijnbhu8
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-4-24
收藏
得分:0 
5  4  1987
2  22 2004
8  9  2000
2  29 1900
3  2  2001
1  8  1999
9  31 2001
9  30 201
12 31 2004
22  9 2000
2  29 2000
输入txt
Day of Year     Calendar Date
    124          05/04/1987
     53          02/22/2004
    222          08/09/2000
     61          03/02/2001
      8          01/08/1999
    366          12/31/2004
     60          02/29/2000
输出txt
2010-04-24 04:46
ijnbhu8
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-4-24
收藏
得分:0 
前面全部搞好了,还剩最后2个,没办法输出啊,请问该怎么弄呢
int writeData (FILE *spOut, int *daysArray,int *yearsArray, int *dayofmonthArray, int numElems)
void caclCalendar(int *daysArray, int *yearsArray, int *dayofmonthArray,int k)
main 函数没法call writeData (FILE *spOut, int *daysArray,int *yearsArray, int *dayofmonthArray, int numElems)
2010-04-24 06:17
ijnbhu8
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-4-24
收藏
得分:0 
顶,请帮忙啊,
最后2个分函数
2010-04-24 08:44
BINGQING
Rank: 2
来 自:武汉
等 级:论坛游民
帖 子:98
专家分:75
注 册:2010-3-29
收藏
得分:20 
路过,虽然我不会,还是帮忙顶一下
2010-04-24 22:53
快速回复:写了一个程序,可以编译,但无法运行,求指教,谢谢,急
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023449 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved