无论如何要逐行读取文件? [英] Anyway to read file line by line ?

查看:54
本文介绍了无论如何要逐行读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.dat文件将包含以下信息。


///////////

首先

0x04

0x05

0x06


第二

0x07

0x08

0x09

第三个

0x0E

0x0F

0x0D

///////////


在我的主程序中,它将打开此dat文件,逐行读取。

当它点击我正在搜索的字符串(例如First)时,程序

将知道下一行将是要存储的变量。

是否有任何C函数逐行读取文件?请给我一些

线索。非常感谢。


Abby。

My .dat file will contain information like below.

///////////
First
0x04
0x05
0x06

Second
0x07
0x08
0x09

Third
0x0E
0x0F
0x0D
///////////

In my main program, it will open this dat file, read line by line.
When it hits the string I''m searching for (e.g. "First"), the program
will know that the next line will be the variables to be stored. Are
there any C function to read file line by line? Please give me some
clue. Thanks a lot.

Abby.

推荐答案

2003年8月1日15:43:46 -0700 , ab*****@yahoo.com (Abby)写道:
On 1 Aug 2003 15:43:46 -0700, ab*****@yahoo.com (Abby) wrote:
我的.dat文件将包含如下信息。

///////////
首先
0x04
0x05
0x06

第二个
0x07
0x08
第三个
0x0E
0x0F
0x0D
///////////

在我的主程序中,它将打开这个数据文件,逐行读取。
当它击中字符串我''在搜索(例如First)时,程序将知道下一行将是要存储的变量。是否有任何C函数逐行读取文件?请给我一些
线索。非常感谢。
My .dat file will contain information like below.

///////////
First
0x04
0x05
0x06

Second
0x07
0x08
0x09

Third
0x0E
0x0F
0x0D
///////////

In my main program, it will open this dat file, read line by line.
When it hits the string I''m searching for (e.g. "First"), the program
will know that the next line will be the variables to be stored. Are
there any C function to read file line by line? Please give me some
clue. Thanks a lot.



查看fgets功能。


-

Al Balmer

Balmer Consulting
重新* ***********************@att.net




" Abby" < AB ***** @ yahoo.com>在消息中写道

"Abby" <ab*****@yahoo.com> wrote in message
是否有任何C函数逐行读取文件?请给我一些
线索。非常感谢。
Are there any C function to read file line by line? Please give me some
clue. Thanks a lot.



fgets()读取一行,如果你知道它的最大长度。


它可能更好使用fscanf()。有点像printf(),它需要一种格式

字符串,它本身就是一种语言。


fgets() reads a line, if you know the maximum length it can be.

It is maybe better to use fscanf(). A bit like printf(), it takes a format
string that is a little language in its own right.




Abby < AB ***** @ yahoo.com>在消息中写道

news:b4 ************************** @ posting.google.c om ...

"Abby" <ab*****@yahoo.com> wrote in message
news:b4**************************@posting.google.c om...
我的.dat文件将包含如下信息。

///////////
首先
0x04 0x05
0x06
第二个
0x07
0x08
0x09

第三个
0x0E
0x0F
0x0D
///////////

在我的主程序中,它会打开这个dat文件,逐行读取。
它击中我正在搜索的字符串(例如First),程序将知道下一行将是要存储的变量。是否有任何C函数逐行读取文件?请给我一些
线索。非常感谢。

Abby。
My .dat file will contain information like below.

///////////
First
0x04
0x05
0x06

Second
0x07
0x08
0x09

Third
0x0E
0x0F
0x0D
///////////

In my main program, it will open this dat file, read line by line.
When it hits the string I''m searching for (e.g. "First"), the program
will know that the next line will be the variables to be stored. Are
there any C function to read file line by line? Please give me some
clue. Thanks a lot.

Abby.




您可以使用fgets()从文件中读取行。

在这种情况下,如果需要提取十六进制代码的值(如0x0E,

0x0F)。您可以使用sscanf()来帮助您。

fgets(stringbuffer,20,fp);

sscanf(stringbuffer,"%X",& var1);


-

杰夫



You can use fgets( ) to read the line from file.
In this case, if you need to extract the value of hex code (like 0x0E,
0x0F ). You can use sscanf( ) to help you.
fgets( stringbuffer, 20, fp);
sscanf( stringbuffer, "%X", &var1);

--
Jeff


这篇关于无论如何要逐行读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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