| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1643 人关注过本帖
标题:fopen读取不了文件
只看楼主 加入收藏
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
结帖率:91.43%
收藏
已结贴  问题点数:20 回复次数:13 
fopen读取不了文件
程序代码:
#include<iostream>
#include<stdio.h>
#include<string.h>

//void main_1(int *n_file_, FILE *open, FILE *write_8, FILE *write_9, FILE *write_10, FILE *write_11, FILE *write_12, FILE *write_13, FILE *write_14, FILE *write_15, FILE *write_16);
void main_1(int * n_file_, FILE * open, FILE ** f_write_);
void file_write(unsigned char *, FILE *);
int length(unsigned char *a);//可以设定多个条件
int main()
{
    FILE *f_open = NULL;//打开目标文件,可以改成把文件拖进来的相对路径
    int n_file_[9] = { 0 };
    if (fopen("test.txt","r+")==NULL)
        puts("打开文件成功\n\n");
    else
    {
        puts("打开文件失败\n\n");
        return 0;
    }

    FILE *f_write_[9] = { NULL };//生成的文件
    f_write_[0] = fopen("length_1_8", "wb+");
    f_write_[1] = fopen("length_9", "wb+");
    f_write_[2] = fopen("length_10", "wb+");
    f_write_[3] = fopen("length_11", "wb+");
    f_write_[4] = fopen("length_12", "wb+");
    f_write_[5] = fopen("length_13", "wb+");
    f_write_[6] = fopen("length_14", "wb+");
    f_write_[7] = fopen("length_15", "wb+");
    f_write_[8] = fopen("length_over15", "wb+");
    //main_1读取数据,分别写入相对于的文件
    main_1(n_file_, f_open, f_write_);

    //    cul(f_write_[0],n_file_[0]);//目标文件;文件存储长度


    fclose(f_open);
    for (int i = 0; i < 9; i++)
        fclose(f_write_[i]);
    return 0;

}


//void main_1(int *n_file_, FILE *open, FILE *write_8, FILE *write_9, FILE *write_10, FILE *write_11, FILE *write_12, FILE *write_13, FILE *write_14, FILE *write_15, FILE *write_16)
void main_1(int * n_file_, FILE * open, FILE ** file)
{
    //    FILE *file[9] = { write_8, write_9, write_10, write_11, write_12, write_13, write_14, write_15, write_16 };
    unsigned char temp[20];
    int i;
    while (!feof(open))//判断是否到文件尾部
    {
        fscanf(open, "%s ", temp);//从文件读取一个字符串
        i = length(temp);//根据字符串长度确定输入哪一个文件,若返回值为0,则跳过这个字符串
        if (i == 0)
            continue;

        else if (i < 9)//写入对应的文件
        {
            file_write(temp, file[0]);
            n_file_[0]++;
        }
        else if (i>15)
        {
            file_write(temp, file[8]);
            n_file_[8]++;
        }
        else
        {
            file_write(temp, file[i - 8]);
            n_file_[i - 8]++;
        }
    }

}

int length(unsigned char *a)//可以设定多个条件
{
    static int n = 0;
    if (n++ % 5 != 2)
        return 0;
    return strlen((char *)a);

}
void file_write(unsigned char * a, FILE * file)
{
    fprintf(file, "%s", a);
    fprintf(file, " ");
}

昨天程序调试的时候还能正常运行,今天早上把一个200M左右的文件进行操作,没成功;之后就出现了无法读取文件的情况:代码调试以后,f_open总是无法读取到内存然后就结束了。
搜索更多相关主题的帖子: color 
2015-01-22 09:23
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:20 
文件太大了吧

DO IT YOURSELF !
2015-01-22 09:31
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
回复 2楼 wp231957
后来改成只有1K不到的文件,还是这个问题。
2015-01-22 09:35
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
 if (fopen("test.txt","r+")==NULL)
  改成   
if (fopen("test.txt","r+")!=NULL)
或者   
if ((f_open=fopen("test.txt","r+"))!=NULL)


问题一样,f_open显示:<无法读取内存>
2015-01-22 09:38
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
 if (fopen("test.txt","r+")==NULL)
  改成   
if (fopen("test.txt","r+")!=NULL)
或者   
if ((f_open=fopen("test.txt","r+"))!=NULL)


问题一样,f_open显示:<无法读取内存>
2015-01-22 09:39
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
 if (fopen("test.txt","r+")==NULL)
  改成   
if (fopen("test.txt","r+")!=NULL)
或者   
if ((f_open=fopen("test.txt","r+"))!=NULL)


问题一样,f_open显示:<无法读取内存>
2015-01-22 09:39
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
 if (fopen("test.txt","r+")==NULL)
  改成   
if (fopen("test.txt","r+")!=NULL)
或者   
if ((f_open=fopen("test.txt","r+"))!=NULL)


问题一样,f_open显示:<无法读取内存>
2015-01-22 09:39
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
回复 2楼 wp231957
重建一个工程以后重启就好了。不知道为什么
2015-01-22 09:54
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
莫名其妙的故障很多  你是不是用的调试模式(DEBUG模式) 而不是实模啊(RELEASE模式)

DO IT YOURSELF !
2015-01-22 10:00
lyl930130
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:323
专家分:111
注 册:2013-5-13
收藏
得分:0 
回复 9楼 wp231957
用的就是DEBUG模式。也没搞明白为什么突然就用不了了。
fopen打开文件我这里测超过16K的打不开
2015-01-22 10:11
快速回复:fopen读取不了文件
数据加载中...
 
   



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

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