| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3338 人关注过本帖
标题:c语言变量莫名其妙的被清零是怎么回事?
只看楼主 加入收藏
yang4055
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-8-18
收藏
 问题点数:0 回复次数:8 
c语言变量莫名其妙的被清零是怎么回事?
我在外部文件中用一个指针指向了一个内存,并赋值,但在主函数中调用时却莫名地被清零了,这是怎么回事?
搜索更多相关主题的帖子: c语言 变量 内存 赋值 指针 
2008-08-18 17:14
爱喝牛奶的猫咪
Rank: 1
来 自:QQ群46520219
等 级:禁止访问
帖 子:513
专家分:0
注 册:2008-6-16
收藏
得分:0 
我也不知道你想说什么回事


[color=white]<" border="0" />>
2008-08-18 17:18
s54661559
Rank: 1
来 自:廣州
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-8-16
收藏
得分:0 
LZ说得好深奥喔
2008-08-18 17:21
canfaint
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-8-10
收藏
得分:0 
楼主..具体点行么?
或者把代码贴出来也好啊..
2008-08-19 12:14
hundnn
Rank: 1
等 级:新手上路
帖 子:123
专家分:0
注 册:2007-8-23
收藏
得分:0 
外部变量在定义时如果没有赋值,默认值为0.跟局部变量不一样/.


我只能告诉你这些,
因为我没看懂你在说什么
2008-08-19 16:16
weijincheng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-1
收藏
得分:0 
c语言变量莫名其妙被改变
#include<stdio.h>
#include<math.h>

int AADT=1992;   /*AADT*/
double avaxle=2.54;  /*axle number per truck*/
double lane=0.5;           /*lane coefficient*/
double direction=0.7;      /*direction coefficient*/

double PSIGLE=57.1;
double PTRADEM=34.5;
double PTRIDEM=8.4;  /*Traffic composition*/



double distribution[100];

int section;

void main()
{
 int i,j,k,l,month,day,hour;
 double temperature=0.0;  /* for read the everyday temperature*/
 
 double yeartraffic; /* total year traffic*/

 double ptemperature;
 double ns,nr;

 double h; /* pavement thickness*/
 double z; /* half pavement thickness*/
 double modulus,strain;
 double c=0.435373; /* fatigue function*/

 double d,damage; /*cumulative damage*/
 double n,nn; /* Miner hypothisis*/
 double monthadjust[12]; /*for read the month traffic adjust coefficient*/
 double houradjust[24];  /*for read the day traffic adjust coefficient */

double singleweight[50],singlepercent[50];
double trademweight[50],tradempercent[50];
double tridemweight[50],tridempercent[50];

 int days; /*month days*/

 int SN=0,TAN=0,TIN=0;
 

 FILE *ft;
 FILE *fp;
 FILE *fs;
 FILE *fr;

 printf("Please input pavement structure number(1,2,3,4,5):\n");
 scanf("%d",&section);
 if(section==1) h=50;
 if(section==2) h=38;
 if(section==3) h=38;
 if(section==4) h=33;
 if(section==5) h=15;
 z=h/2;
 yeartraffic=AADT*avaxle*365*lane*direction; /*year total traffic*/

 fs=fopen("month.txt","r");
 if(fs==NULL)printf("file open error!\n");
 while(!feof(fs))
 {fscanf(fs,"%d %lf\n",&i,&ns);
  monthadjust[i]=ns;
  printf("month=%d,coefficient=%f\n",i,monthadjust[i]);
  }
  fclose(fs);
  system("pause"); /* to read the month traffic adjust coefficient*/

printf("month=%f\n",monthadjust[12]);system("pause");
 fs=fopen("hour.txt","r");
 if(fs==NULL) printf("file open errors!\n");
 while(!feof(fs))
  {fscanf(fs,"%d %lf\n",&i,&ns);
   houradjust[i]=ns;
   printf("hour=%d,coefficient=%f\n",i,houradjust[i]);
   }
   fclose(fs);
   system("pause"); /*to read the day traffic adjust coefficient*/
   printf("month=%f\n",monthadjust[12]);system("pause");
   for(i=1;i<=12;i++)
   printf("%f\n",monthadjust[i]);

}
monthadjust[i]变量当i=12时被没名奇妙的变为houradjust[i]一样的数是怎么回事?
c中的变量还会冲突或自动改变吗?
2008-09-01 09:02
weijincheng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-1
收藏
得分:0 
求助
c语言变量莫名其妙被改变
#include<stdio.h>
#include<math.h>

int AADT=1992;   /*AADT*/
double avaxle=2.54;  /*axle number per truck*/
double lane=0.5;           /*lane coefficient*/
double direction=0.7;      /*direction coefficient*/

double PSIGLE=57.1;
double PTRADEM=34.5;
double PTRIDEM=8.4;  /*Traffic composition*/



double distribution[100];

int section;

void main()
{
int i,j,k,l,month,day,hour;
double temperature=0.0;  /* for read the everyday temperature*/

double yeartraffic; /* total year traffic*/

double ptemperature;
double ns,nr;

double h; /* pavement thickness*/
double z; /* half pavement thickness*/
double modulus,strain;
double c=0.435373; /* fatigue function*/

double d,damage; /*cumulative damage*/
double n,nn; /* Miner hypothisis*/
double monthadjust[12]; /*for read the month traffic adjust coefficient*/
double houradjust[24];  /*for read the day traffic adjust coefficient */

double singleweight[50],singlepercent[50];
double trademweight[50],tradempercent[50];
double tridemweight[50],tridempercent[50];

int days; /*month days*/

int SN=0,TAN=0,TIN=0;


FILE *ft;
FILE *fp;
FILE *fs;
FILE *fr;

printf("Please input pavement structure number(1,2,3,4,5):\n");
scanf("%d",&section);
if(section==1) h=50;
if(section==2) h=38;
if(section==3) h=38;
if(section==4) h=33;
if(section==5) h=15;
z=h/2;
yeartraffic=AADT*avaxle*365*lane*direction; /*year total traffic*/

fs=fopen("month.txt","r");
if(fs==NULL)printf("file open error!\n");
while(!feof(fs))
{fscanf(fs,"%d %lf\n",&i,&ns);
  monthadjust[i]=ns;
  printf("month=%d,coefficient=%f\n",i,monthadjust[i]);
  }
  fclose(fs);
  system("pause"); /* to read the month traffic adjust coefficient*/

printf("month=%f\n",monthadjust[12]);system("pause");
fs=fopen("hour.txt","r");
if(fs==NULL) printf("file open errors!\n");
while(!feof(fs))
  {fscanf(fs,"%d %lf\n",&i,&ns);
   houradjust[i]=ns;
   printf("hour=%d,coefficient=%f\n",i,houradjust[i]);
   }
   fclose(fs);
   system("pause"); /*to read the day traffic adjust coefficient*/
   printf("month=%f\n",monthadjust[12]);system("pause");
   for(i=1;i<=12;i++)
   printf("%f\n",monthadjust[i]);

}
monthadjust[i]变量当i=12时被没名奇妙的变为houradjust[i]一样的数是怎么回事?
c中的变量还会冲突或自动改变吗?
2008-09-01 09:03
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
printf("month=%f\n",monthadjust[12]);

monthajust只有0~11这12个元素,你引用12干嘛?

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-09-01 10:54
qfyzy
Rank: 2
等 级:论坛游民
威 望:1
帖 子:380
专家分:86
注 册:2008-2-17
收藏
得分:0 
0-11为合法下标。12越界,至于为什么会和别的一样,与数据存储的细节有关。

当对C的经验增加时,它会显的很好用.----Dennis M Ritche如是说
2008-09-01 12:35
快速回复:c语言变量莫名其妙的被清零是怎么回事?
数据加载中...
 
   



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

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