| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
免费IT实战开发视频教程合集分享千里之行 始于足下
共有 182 人关注过本帖
标题:数组文本写入写不进去是什么问题
只看楼主 加入收藏
tomye
Rank: 2
等 级:论坛游民
帖 子:22
专家分:10
注 册:2017-12-1
结帖率:50%
  问题点数:0  回复次数:1   
数组文本写入写不进去是什么问题
float s = 0;
    FILE *g;
    g = fopen("时空图.txt", "a");
    for (i = 0; i < car_num; i++)
    {
        temp_1 = p[i];
        speed = v[i][temp_1];
        gap = FindFront(i);
        if (speed + 1 <= vmax)
            speed++;
        if (speed > gap)
            speed = gap;
        if (speed > 0 && rand_double() <= pi)
            speed--;
        temp_2 = (temp_1 + speed) % lane;        //位置更新
        p[i] = temp_2;
        v[i][temp_2] = speed;
        a[i] = speed - v[i][temp_1];
        if (speed > 0)
            v[i][temp_1] = -1;
        if (a[i] > 0 || a[i] == 0)
        {
            tor[i] = (mg*(0.0076 + 0.000056*speed) + 0.5*0.3*1.2258*8.25*speed * speed + 1.1*mg / 10 * a[i])*r;  //扭矩
            pe[i] = tor[i] / (0.8*0.95*0.8)*(speed / r*0.8*0.95);
            pm[i] = pe[i] / (367.1 * 7);
        }
        //fprintf(g, "第1辆车的油耗:%2f\n", pm[0]);
        /*if (temp_2 == p[(i + 1) % lane])
        {
        printf("撞车了,位置为:%2d ,编号为;%2d", p[i], i);
        }*/
        s += pm[i];
    }
    fprintf(g, "耗油:%2f\n", s/time_count);


结果是文本文件g中什么也没有
2018-09-16 11:25
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:163
帖 子:6314
专家分:27603
注 册:2014-5-20
  得分:0 
先化简测试一下看看问题所在
#include <stdio.h>
main()
{
    FILE *g;
    g = fopen("时空图.txt", "a");
    fprintf(g, "耗油:%2f\n", 123.456);
    fclose(g);
}
2018-09-18 05:57







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

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