不读数据 [英] Not reading data
问题描述
另一个新手问题:
我如何开始阅读数据,但从第x行开始下来
清单?换句话说,如何跳过第一行而不读取这些值?
谢谢
-
通过 http://dbforums.com 发布
推荐答案
djj858< me ********* @ dbforums.com>写道:
djj858 <me*********@dbforums.com> wrote:
我如何开始读取数据,但是从第x行开始下一个
列表?换句话说,如何跳过第一行而不读取这些值?
How do I begin reading data, but starting from the xth line down a
list? In other words, how do I skip the first lines and not read in
those values?
[假设你在谈论文本文件]
除非您已经为文件维护索引,否则以下
适用:
要跳过你必须计算它们。计算行数你必须计算
行分隔符(''newlines'')。要计算换行符,您必须阅读
数据,例如:
/ *未经测试的代码! * /
#include< stdio.h>
int SkipLines(FILE * fp,unsigned int lines)
{
int c = 0;
while(lines&&(c = fgetc(fp))!= EOF)
if(c ==''\ n'')
行 - ;
返回c == EOF? 0:1;
}
问候
-
Irrwahn
(ir*******@freenet.de)
[Assuming you''re talking about text files]
Unless you''re already maintaining an index to your file, the following
applies:
To skip lines you must count them. To count lines you have to count
line delimiters (''newlines''). To count newlines, you have to read the
data, e.g:
/* Untested code! */
#include <stdio.h>
int SkipLines( FILE *fp, unsigned int lines )
{
int c = 0;
while ( lines && (c = fgetc( fp )) != EOF )
if ( c == ''\n'' )
lines--;
return c == EOF ? 0 : 1;
}
Regards
--
Irrwahn
(ir*******@freenet.de)
djj858< me ********* @ dbforums.com>潦草地写道:
djj858 <me*********@dbforums.com> scribbled the following:
另一个新手问题:
我如何开始读取数据,但是从第x行开始下一个
列表?换句话说,如何跳过第一行而不读取这些值?
Another newbie question: How do I begin reading data, but starting from the xth line down a
list? In other words, how do I skip the first lines and not read in
those values?
通常情况下,你不能。你不得不照看你读过的第一行(x-1)
来假装它。如果我知道你是如何阅读
的数据,那么我可以提供更多的帮助。
-
/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \
\ - http://www.helsinki.fi/~palaste ---------------------规则! -------- /
"''所谓的''意味着'''这有很长的解释,但我没有
时间在这里解释一下。''"
- JIPsoft
Usually, you can''t. You have to fake it by not caring at the first (x-1)
lines you read. I could be of more help if I knew how you were reading
the data, and from what.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"''So called'' means: ''There is a long explanation for this, but I have no
time to explain it here.''"
- JIPsoft
一些澄清:
例如正在阅读的文件:
备注这些是一些垃圾
备注持续一段时间
ATOM 123 123 2312
ATOM 123 123 2312
我想跳过备注在开始时读取ATOM值。
我现在这样做的方法是手动从文件中手动删除REMARKs
,然后将其输入程序使用
fscanf。必须有更好的方法!
-
发表于 http://dbforums.com
这篇关于不读数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!