| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2848 人关注过本帖
标题:fopen()时出现error C2099: initializer is not a constant
只看楼主 加入收藏
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:12 
fopen()时出现error C2099: initializer is not a constant
void main()
{
    int i,s;
    FILE *fp0,*fp;
    struct position *agent_pos,agent[Nagent];
    double d_agent[Nagent];
    double toa[Nagent];

    double err=0;
    agent_pos=0;

    /*调用g_s()函数,获得存储了相应用于SPA运算的样值,即原来的i=1:1:50*/
    void g_s();
    /*调用g_p(),获得初始码书,用于矢量量化*/
    void g_p();

    /*打开文件,以准备更新矢量量化所需的各个样值*/
    fp0=fopen("C:\\w_samp.txt","w+");
    if(fp0==NULL)   
    {
        printf("cannot opent the file \n");
        exit(0);
    }  
.....
}
E:程序\co_location\coor_main.c(59) : error C2099: initializer is not a constant 红色的部分
是什么原因呢?
搜索更多相关主题的帖子: constant fopen initializer not 
2010-10-15 18:17
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:4 
C:\\w_samp.txt 文件存在吗?
2010-10-15 18:22
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 2楼 hahayezhe
存在,而且就算不存在,用的是“w”也应该可以的吧
2010-10-15 18:25
日的起烟烟
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:137
专家分:129
注 册:2010-2-27
收藏
得分:4 
initializer is not a constant

初始化值不是一个常数

2010-10-15 19:11
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 3楼 蓝夕
这句话是这样理解的
2010-10-15 19:30
我菜119
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:938
专家分:1756
注 册:2009-10-17
收藏
得分:4 
你把你的整个代码拷贝过来看看吧!你的这个问题怎么好像很奇怪呢

愿用余生致力编程
2010-10-15 19:39
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 6楼 我菜119
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include"v_quatization.h"
#include"dist.h"
#include"spa.h"
#include"sample_g.h"
#include"p_history.h"
#define Nagent 147
#define Nanchor 6
/*已知坐标的节点位置*/
const struct position anchor[Nanchor]={{100,100},{100,200},{100,300},{300,100},{300,200},{300,300}};
/**基站位置固定在中心*/
const double b_x=200;
const double b_y=200;

void main()
{
    int i,s;
    FILE *fp0,*fp;
    struct position *agent_pos,agent[Nagent];
    double d_agent[Nagent];
    double toa[Nagent];

    double err=0;
    agent_pos=0;

    /*调用g_s()函数,获得存储了相应用于运算的样值,即原来的i=1:1:50*/
    void g_s();
    /*调用g_p(),获得初始码书,用于矢量量化*/
    void g_p();

    /*打开文件,以准备更新矢量量化所需的各个样值*/

    /*读取需要定位的点的真实位置和测量距离测量时间*/
    fp=fopen("C:\\agent_pos.txt","r");
    if(fp==NULL)   
    {
        printf("cannot opent the file \n");
        exit(0);
    }
    for(i=0;i<Nagent;i++)
    {
        fscanf(fp,"%lf,%lf,%lf,%lf\n",&agent[i].x,&agent[i].y,&d_agent[i],&toa[i]);
    }
    agent_pos=spa(d_agent[Nagent],toa[Nagent]);

    /*计算误差,并更新w_samp.txt*/
    fp0=fopen("C:\\w_samp.txt","w");
    if(fp0==NULL)   
    {
        printf("cannot opent the file \n");
        exit(0);
    }  
    for(i=0;i<Nagent;i++)
    {
        fprintf(fp0,"%lf,%lf,%lf,%lf\n",(*(agent_pos+i)).x,(*(agent_pos+i)).y,d_agent[i],toa[i]);
        err=dist((*(agent_pos+i)).x,(*(agent_pos+i)).y),&agent[i].x,agent[i].y))*dist((*(agent_pos+i)).x,(*(agent_pos+i)).y),&agent[i].x,agent[i].y));
    }
    rewind(fp0);
    err/=Nagent;
    printf("the error of location is: %lf\n",err);
    fclose(fp);
    fclose(fp0);
}
这是主函数
2010-10-15 19:47
日的起烟烟
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:137
专家分:129
注 册:2010-2-27
收藏
得分:0 
编译错误吗?

2010-10-15 20:45
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 8楼 日的起烟烟
嗯,生成.obj时
2010-10-17 11:33
逐渐学习
Rank: 6Rank: 6
等 级:侠之大者
帖 子:113
专家分:454
注 册:2010-9-26
收藏
得分:4 
把fp0=fopen("C:\\w_samp.txt","w");这个单独编个小程序看看出错不?如果不出错,看看是不是其它部分引起的。

帮人《---》帮己
2010-10-17 13:08
快速回复:fopen()时出现error C2099: initializer is not a constant
数据加载中...
 
   



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

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