文件访问 - 设计思路。 [英] file access - design thoughts.

查看:72
本文介绍了文件访问 - 设计思路。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能就这个设计查询得到一些建议,看看我是否朝着正确的方向前进。$

我想阅读多行文件,然后搜索一个

特定字符,将句子分成单独的单词。

一旦完成,我会对它们进行排序。


我想过使用fgets但是线路可能会非常长而且我不知道它的n个字符长度是多少排在队伍中。


使用fgetc似乎是更好的选择并将每个角色放入数组

所以我可以遍历数组。


但是,如果我将每个角色放入一个数组中,我仍然不知道如何制作数组




有更好的策略吗?


Jay

Hi, I''m hoping to get some advice on this design query to see if I''m
heading in the right direction.

I would like to read a file of many lines and then search for a
particular character to break up the sentence into separate words.
Once done I will sort them.

I thought of using fgets but the line could be very very long and I
won''t know it''s length of n characters that could be in a line.

Using fgetc seems the better bet and put each character into an array
so I can traverse the array.

However,if I put each character into an array, I still won''t know how
large to make the array.

Is there a better strategy ?

Jay

推荐答案

J。******* @ gmail.com 写道:

我希望能在这个设计查询上得到一些建议,看看我是否朝着正确的方向前进。$

我会喜欢阅读多行文件,然后搜索一个

特定字符,将句子分成单独的单词。

一旦完成,我会对它们进行排序。


我想过使用fgets但是线路可能会非常长而且我不会知道它的n个字符的长度可能是行。


使用fgetc似乎是更好的选择并将每个角色放入一个数组

所以我可以遍历数组。


但是,如果我将每个角色放入一个数组中,我仍然不知道如何制作数组




是有更好的策略吗?
Hi, I''m hoping to get some advice on this design query to see if I''m
heading in the right direction.

I would like to read a file of many lines and then search for a
particular character to break up the sentence into separate words.
Once done I will sort them.

I thought of using fgets but the line could be very very long and I
won''t know it''s length of n characters that could be in a line.

Using fgetc seems the better bet and put each character into an array
so I can traverse the array.

However,if I put each character into an array, I still won''t know how
large to make the array.

Is there a better strategy ?



如果可移植性不是问题,你可能会更好地使用你的

操作系统'' s内存的方式映射文件,只需使用

结果为数组。


-

Ian Collins。

If portability isn''t an issue, you will probably be better of using your
operating system''s means of memory mapping the file and simply using the
result as an array.

--
Ian Collins.




< J. ******* @ gmail.comwrote in message

news:11 ****************** ***@w5g2000hsg.googlegrou ps.com ...

<J.*******@gmail.comwrote in message
news:11*********************@w5g2000hsg.googlegrou ps.com...

您好,我希望就此设计查询获得一些建议,看看我是不是m

朝着正确的方向前进。


我想阅读多行文件,然后搜索

将句子分成单独的单词的特殊字符。

一旦完成,我会对它们进行排序。


我想过使用fgets但是这行可能非常非常我和你不知道它的n个字符的长度可能会排成一行。


使用fgetc似乎是更好的选择把每个角色放到一个数组中

所以我可以遍历数组。


但是,如果我将每个字符放入一个数组中,我仍然不会知道如何

larg e制作阵列。


有更好的策略吗?
Hi, I''m hoping to get some advice on this design query to see if I''m
heading in the right direction.

I would like to read a file of many lines and then search for a
particular character to break up the sentence into separate words.
Once done I will sort them.

I thought of using fgets but the line could be very very long and I
won''t know it''s length of n characters that could be in a line.

Using fgetc seems the better bet and put each character into an array
so I can traverse the array.

However,if I put each character into an array, I still won''t know how
large to make the array.

Is there a better strategy ?



Google for ggets和Chuck Falconer。

Chuck,这个组中的一个注册表,已经准确地提供了你想要的东西。我b $ b完全没有权利,当然是无所事事。

Google for ggets and Chuck Falconer.
Chuck, a reg in this group, has kindly provided exactly what you want. I
believe entirely rights free, certainly for nothing.


J。******* @ gmail.com 写道:

>

我希望能在这个设计查询上得到一些建议,看看我是否朝着正确的方向前进。$

我想阅读多行文件,然后搜索一个

特定字符,将句子分成单独的单词。

一旦完成,我会对它们进行排序。


我想过使用fgets但是线路可能非常长而且我不知道它的长度是n个字符可以排成一行。


使用fgetc似乎是更好的选择并将每个角色放入一个数组

所以我可以遍历数组。


但是,如果我将每个角色放入一个数组中,我仍然不知道如何制作数组




有更好的策略吗?
>
Hi, I''m hoping to get some advice on this design query to see if I''m
heading in the right direction.

I would like to read a file of many lines and then search for a
particular character to break up the sentence into separate words.
Once done I will sort them.

I thought of using fgets but the line could be very very long and I
won''t know it''s length of n characters that could be in a line.

Using fgetc seems the better bet and put each character into an array
so I can traverse the array.

However,if I put each character into an array, I still won''t know how
large to make the array.

Is there a better strategy ?



get_line使用getc读取行,并重新分配以调整数组的大小。

在(size_t)-1)字节处截断行。

http:// www。 mindspring.com/~pfilandr/...ine/get_line.c


-

pete

get_line uses getc to read lines, and realloc to size the array.
Truncates lines at (size_t)-1) bytes.

http://www.mindspring.com/~pfilandr/...ine/get_line.c

--
pete


这篇关于文件访问 - 设计思路。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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