| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2848 人关注过本帖
标题:fopen()时出现error C2099: initializer is not a constant
取消只看楼主 加入收藏
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
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
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 2楼 hahayezhe
存在,而且就算不存在,用的是“w”也应该可以的吧
2010-10-15 18:25
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 3楼 蓝夕
这句话是这样理解的
2010-10-15 19:30
蓝夕
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: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 8楼 日的起烟烟
嗯,生成.obj时
2010-10-17 11:33
蓝夕
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2010-10-15
收藏
得分:0 
回复 11楼 BlueGuy
那两个函数是无返回值的函数,直接写g_c()这样报错,说是类型重定义。
现在把这样个函数去掉了,又出现了新的问题。麻烦帮忙看一下https://bbs.bccn.net/thread-323171-1-1.html
2010-10-17 18:49
快速回复:fopen()时出现error C2099: initializer is not a constant
数据加载中...
 
   



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

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