龟etc没有开始大的txt文件的开头 [英] fgetc not starting at beginning of large txt file

查看:128
本文介绍了龟etc没有开始大的txt文件的开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C工作,并有一个文本文件,它是我试图用龟etc 读取617KB。出于某种原因,龟etc 随机文件内开始。我试图移动文件指针来获得与 fseek的开头没有成功。我可以得到龟etc 工作,较小的文件以罚款。任何帮助是AP preciated。

样品输入了25,000行类似的数据:

 产品
23 660
2366 3
237 09
2 3730
23734
23 773
241 46

来源:

 的#define _CRT_SECURE_NO_WARNINGS
#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&stdlib.h中GT;无效打印(FILE *类){    INT CH ='A';    而((CH =龟etc(类))!= EOF){        的printf(%C,CH);
    }    的getchar();
}诠释主要(无效){    FILE *类别=的fopen(MYFILE,R);    如果(类别== NULL){
        看跌期权(类别找不到文件);
    }
    其他{        打印(类);
        FCLOSE(类);        返回0;
    }}


解决方案

我怀疑问题出在其它地方。

如果从该程序的输出回事?如果你把它发送到控制台,其滚动缓冲区将不会大到足以容纳整个文件。也许它只是看起来的如龟etc()在奇怪的地方开始。

尝试从该程序的输出转移到一个新的文本文件,并与输入文件的大小,例如比较这文件的大小:

  ./ category_print> output.txt的

I am working in C and have a text file that is 617kb that I am trying to read with fgetc. For some reason fgetc is starting randomly within the file. I have tried moving the file pointer to get beginning with fseek with no success. I can get fgetc work to fine with smaller files. Any help is appreciated.

Sample input is 25,000 lines of data similar to:

Product
23 660
2366 3
237 09
2 3730
23734
23 773
241 46

Source:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void print(FILE *category){

    int ch = 'a';

    while ((ch = fgetc(category)) != EOF){

        printf("%c", ch);
    }

    getchar();
}

int main(void){

    FILE *category = fopen("myFile", "r");

    if (category == NULL){
        puts("category file not found");
    }
    else{

        print(category);    
        fclose(category);

        return 0;
    }

}

解决方案

I suspect the problem lies elsewhere.

Where is the output from this program going? If you're sending it to the console, its scrollback buffer won't be large enough to contain the whole file. Maybe it just looks like fgetc() is starting in an odd place.

Try diverting the output from this program to a new text file and compare the size of this file with the size of the input file, e.g.:

./category_print >output.txt

这篇关于龟etc没有开始大的txt文件的开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆