读表 [英] Reading a table
问题描述
您好,
我的C有点生疏(.NET程序员通常但需要在
C中执行此操作)我需要阅读设置为表格的文本文件。
文件的一般形式是
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
我需要逐行读取文件并最终解析出文件中的每个文件并存储在与特定
行对应的数组中。 array1 [1]将是第一行中的第一个条目,依此类推
等等。
任何建议都会很棒!
谢谢。
Hello,
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
I need to read the file line by line and eventually parse out each
piece of the file and store in arrays that correspond to the specific
line. array1[1] would be the first entry in the first line and so on
and so forth.
Any suggestions would be great!
Thanks.
推荐答案
11月26日上午11:04,Stephen.Schoenber ... @ gmail.com写道:
On Nov 26, 11:04 am, Stephen.Schoenber...@gmail.com wrote:
你好,
我的C有点生疏(.NET程序员通常但需要在
C)我需要读入一个设置为表格的文本文件。
文件的一般形式是
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
我需要逐行读取文件并最终解析出文件中的每个文件并存储在与特定
行对应的数组中。 array1 [1]将是第一行中的第一个条目,依此类推
等等。
任何建议都会很棒!
Hello,
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
I need to read the file line by line and eventually parse out each
piece of the file and store in arrays that correspond to the specific
line. array1[1] would be the first entry in the first line and so on
and so forth.
Any suggestions would be great!
fopen()打开文件。
fgets()一次读一行。
编写你自己的函数来解析它,因为只有你知道格式。
HTH
fopen() to open the file.
fgets() to read in one line at a time.
write your own function to parse it, because only you know the format.
HTH
11月26日,2 :晚上10点,user923005< dcor ... @ connx.comwrote:
On Nov 26, 2:10 pm, user923005 <dcor...@connx.comwrote:
11月26日上午11点04分,Stephen.Schoenber ...... @gmail。 com写道:
On Nov 26, 11:04 am, Stephen.Schoenber...@gmail.com wrote:
你好,
Hello,
我的C有点生疏(.NET程序员通常但需要在
C)中执行此操作,我需要读取设置为表格的文本文件。
文件的一般形式是
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
我需要逐行读取文件并最终解析出文件的每个元素并存储在与特定对应的数组中
行。 array1 [1]将是第一行中的第一个条目,依此类推
等等。
I need to read the file line by line and eventually parse out each
piece of the file and store in arrays that correspond to the specific
line. array1[1] would be the first entry in the first line and so on
and so forth.
任何建议都会很棒!
Any suggestions would be great!
fopen()打开文件。
fgets()一次读一行。
编写你自己的函数来解析它,因为只有你知道格式。
HTH
fopen() to open the file.
fgets() to read in one line at a time.
write your own function to parse it, because only you know the format.
HTH
谢谢!
Thanks!
St **** **************@gmail.com 写道:
St******************@gmail.com wrote:
您好,
我的C有点生疏(.NET程序员通常需要在
C中执行此操作)并且我需要读取设置为表格的文本文件。
文件的一般形式是
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
我需要逐行读取文件并最终解析出文件中的每个文件并存储在与特定
行对应的数组中。 array1 [1]将是第一行中的第一个条目,依此类推
等等。
任何建议都会很棒!
Hello,
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
I need to read the file line by line and eventually parse out each
piece of the file and store in arrays that correspond to the specific
line. array1[1] would be the first entry in the first line and so on
and so forth.
Any suggestions would be great!
C中的数组从0开始索引。如果确定基于1,则可以将第一个数据保留为空索引,但它不是一个过于好的
的想法。
我也会建议一个二维数组,而不是单独的数组
命名为array1这样可以更容易处理,因为整个表格可以将单个行传递给函数或其他任何东西。所以第一个
行是table [0],第一个元素是table [0] [0]。
特别是如果你碰巧知道行数和
列,那么很容易,否则你可能需要一个动态数组。
当然,你仍然需要为元素
自己想出一个数据类型,大概是char *,但是目前还不清楚解析是什么/>
实际上是由。我们需要更多信息。
Brian
Arrays in C are indexed from 0. You can leave the first one empty if
you''re determined to have 1-based indexing, but it''s not an overly good
idea.
I''d also suggest a two-dimensional array, rather than separate ones
named "array1" etc. That makes for easier handling, as the entire table
OR individual rows can be passed to functions or whatever. So the first
row would be table[0], and the first element would be table[0][0].
It''s especially easy if you happen to know the number of rows and
columns going in, otherwise you''ll probably need a dynamic array. Of
course, you still need to come up with a data type for the elements
themselves, presumably char*, but it''s not clear what the parsing
actually consists of. We''d need more information.
Brian
这篇关于读表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!