标题:txt文件的读入
取消只看楼主
七叶草
Rank: 2
等 级:论坛游民
帖 子:19
专家分:30
注 册:2012-2-7
结帖率:33.33%
已结贴  问题点数:40 回复次数:1 
txt文件的读入
#include "stdio.h"
#include "malloc.h"
void main()
{
    int i,m;
    float *data1,*data2,*data3,*data4,*data5,*data6,*data7,*data8,*data9,*data10,*data11;
    FILE *fp1,*fp2;
    fp1=fopen("hd4vsp.txt","r");
    fp2=fopen("yumen.txt","w");
    m=8;
    data1=(float *)malloc(m*sizeof(float));data2=(float *)malloc(m*sizeof(float));
    data3=(float *)malloc(m*sizeof(float));data4=(float *)malloc(m*sizeof(float));
    data5=(float *)malloc(m*sizeof(float));data6=(float *)malloc(m*sizeof(float));
    data7=(float *)malloc(m*sizeof(float));data8=(float *)malloc(m*sizeof(float));
    data9=(float *)malloc(m*sizeof(float));data10=(float *)malloc(m*sizeof(float));
    data11=(float *)malloc(m*sizeof(float));
    for(i=0;i<m;i++)
    {
//        fscanf(fp1,"%f %f %f %f %f %f %f %f %f %f %f",&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i]);
        fscanf(fp1,"%f    %f    %f    %f    %f    %f    %f    %f    %f    %f    %f",&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i],&data1[i]);
    }
    printf("read data is ok!\n");
    for(i=0;i<m;i++)
    {
        fprintf(fp2,"%f %f %f %f %f %f %f %f %f %f %f",data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i],data1[i]);
    }
}
txt文件内容为:文件名就是程序中的那个
4990.000000 4.855436 4.633973 -0.221464 2.691971 2.423000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.100098 4.742641 4.633973 -0.108668 2.691971 2.455000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.200195 4.620002 4.633973 0.013971 2.691971 2.487000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.299805 4.571977 4.633973 0.061995 2.691971 2.473000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.399902 4.533893 4.633973 0.100080 2.691971 2.453000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.500000 4.522658 4.633973 0.111315 2.691971 2.418000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.600098 4.537740 4.633973 0.096232 2.691971 2.380000 2.498630 0.245318 0.999000 0.001000 0.999000
4990.700195 4.572663 4.633973 0.061309 2.691971 2.343000 2.498630 0.245318 0.999000 0.001000 0.999000
执行老是不对。显示错误:
stream!=NULl
搜索更多相关主题的帖子: void include 
2012-03-02 17:23
七叶草
Rank: 2
等 级:论坛游民
帖 子:19
专家分:30
注 册:2012-2-7
得分:0 
这么多高手在线,哪位高手帮帮忙呀。整了两天了还没有出来
2012-03-02 17:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-362058-1-1.html




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

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