| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1126 人关注过本帖
标题:求助!这是怎么回事?
取消只看楼主 加入收藏
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
求助!这是怎么回事?
各位大虾
今天编了一个程序,经过几次修改,终于可以编译生成可执行文件了,但是在运行时又出问题了
出现了“ox00401810”指令引用的“ox33463280”内存。该内存不能为“read”
究竟怎么回事啊?
谢过各位大虾了
谢过所有看帖的人
搜索更多相关主题的帖子: 内存 执行文件 
2009-10-16 22:30
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
我把源码粘出来
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int bYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
int sYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"enter year,month,day:"<<endl;
int year,month,day;
int s1,s2,s,fact;
int i;
s1=(year-1)+((year-1)/4)-((year-1)/400);
cin>>year>>month>>day;
if(year%400&&year%4)
   for(;i<=(month-1);++i)
      {
      cout<<endl;
      s2=s2+bYear[i];
      }
   s2=s2+day;
if(year%400!=0&&year%4!=0)
{
     for(;i<=(month-1);++i)
   {
   s2+=sYear[i];
   }
   s2=s2+day;
}
s=s1+s2;
fact=s%7;
switch(fact)
{
   case 0:
      cout<<"today is sunday";
      break;
   case 1:
      cout<<"today is monday";
      break;
   case 2:
      cout<<"today is tuseday";
      break;
   case 3:
      cout<<"today is wednesday";
      break;
   case 4:
      cout<<"today is thurday";
      break;
   case 5:
      cout<<"today is friday";
      break;
   case 6:
      cout<<"today is saturday";
      break;
   default:cout<<"this program has bugs.";
}
return 0;
}        
 
 
2009-10-16 22:46
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
还是不行啊
2009-10-16 23:07
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
我觉得是数组在调用内存时失败造成的
有这种可能么?
2009-10-17 07:19
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
经过大家的共同努力,我们成功了!下面的源代码是改好的
它的功能是计算任意一天是星期几
请大家分享
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int bYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
int sYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"enter year,month,day:"<<endl;
int year,month,day;
int s1=0,s2=0,s=0,fact=0;
int i;
cin>>year>>month>>day;
s1=(year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400);
if(year%400||year%4)
{
   for(i=0;i<=(month-1);++i)
      {
      s2=s2+bYear[i];
      }   
}
if(year%400!=0||year%4!=0)
{
     for(i=0;i<=(month-1);++i)
     {
        s2=s2+sYear[i];
     }
}
s2=s2+day;
s=s1+s2;
fact=s%7;
switch(fact)
{
   case 0:
      cout<<"today is sunday\n";
      break;
   case 1:
      cout<<"today is monday\n";
      break;
   case 2:
      cout<<"today is tuseday\n";
      break;
   case 3:
      cout<<"today is wednesday\n";
      break;
   case 4:
      cout<<"today is thurday\n";
      break;
   case 5:
      cout<<"today is friday\n";
      break;
   case 6:
      cout<<"today is saturday\n";
      break;
   default:cout<<"this program has bugs.";
}
return 0;
}      
谢谢大家!!!!!!!!!!!

[ 本帖最后由 loookc 于 2009-10-17 13:16 编辑 ]
2009-10-17 12:24
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
以下是引用东海一鱼在2009-10-17 14:17:51的发言:

  声明int fact当然不会自动做unsigned int转换。
  所以我说必须将fact声明为unsigned int型才可以。

  或者就像你所说的自己做一些处理。比如说你可以用数学函数abs求绝对值。

  也可以自定义一个宏:
  #define ...
应该不用
因为根据算“任意一天是星期几的算法看来”fact是不会为负的
2009-10-17 14:44
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
经过测试,上面的程序有误
2009-10-17 15:05
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
改了的
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int bYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
int sYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"enter year,month,day:"<<endl;
int year,month,day;
int s1=0,s2=0,s=0,fact=0;
int i;
cin>>year>>month>>day;
s1=(year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400);
     if((year%4==0)&&(year%100!=0)||(year%400==0))
     {
         for(i=0;i<=(month-2);++i)
         {
         s2=s2+bYear[i];
         }   
     }
     else
     {  
         for(i=0;i<=(month-2);++i)
         {
         s2=s2+sYear[i];
         }
     }
      
s2=s2+day;
s=s1+s2;
fact=s%7;
switch(fact)
{
   case 0:
      cout<<"this day is sunday\n";
      break;
   case 1:
      cout<<"this day is monday\n";
      break;
   case 2:
      cout<<"this day is tuseday\n";
      break;
   case 3:
      cout<<"this day is wednesday\n";
      break;
   case 4:
      cout<<"this day is thurday\n";
      break;
   case 5:
      cout<<"this day is friday\n";
      break;
   case 6:
      cout<<"this day is saturday\n";
      break;
   default:cout<<"this program has bugs.";
}
return 0;
}      
2009-10-17 15:25
loookc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:11
注 册:2009-10-15
收藏
得分:0 
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int bYear[]={31,29,31,30,31,30,31,31,30,31,30,31};
int sYear[]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"enter year,month,day:"<<endl;
int year,month,day;
int s1=0,s2=0,s=0,fact=0;
int i;
cin>>year>>month>>day;
s1=(year-1)+((year-1)/4)-((year-1)/100)+((year-1)/400);
     if((year%4==0)&&(year%100!=0)||(year%400==0))
     {
         for(i=0;i<=(month-2);++i)
         {
         s2=s2+bYear[i];
         }   
     }
     else
     {  
         for(i=0;i<=(month-2);++i)
         {
         s2=s2+sYear[i];
         }
     }
      
s2=s2+day;
s=s1+s2;
fact=s%7;
switch(fact)
{
   case 0:
      cout<<"this day is sunday\n";
      break;
   case 1:
      cout<<"this day is monday\n";
      break;
   case 2:
      cout<<"this day is tuseday\n";
      break;
   case 3:
      cout<<"this day is wednesday\n";
      break;
   case 4:
      cout<<"this day is thurday\n";
      break;
   case 5:
      cout<<"this day is friday\n";
      break;
   case 6:
      cout<<"this day is saturday\n";
      break;
   default:cout<<"this program has bugs.";
}
return 0;
}      
大家再看看
2009-10-17 22:21
快速回复:求助!这是怎么回事?
数据加载中...
 
   



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

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