开发者

Basic C question: Reading a Subfile in C

开发者 https://www.devze.com 2023-03-15 23:16 出处:网络
I have an xml like file and I have to read only a part of the file.(subfile). Then I have to search this subfile for some \"strings\".

I have an xml like file and I have to read only a part of the file.(subfile). Then I have to search this subfile for some "strings".

I thought of reading a file from a start pointer till an end pointer(which would be the subfile). Then I should work with th开发者_开发知识库is subfile and inspect line by line of the subfile using fgets().

The trouble is, fgets seems to take only a file pointer as parameter :( Any ideas??


You can use mmap() on UNIX/Linux to map a file to memory. This should make it easier to isolate a part of the file and work with it. Your xml library will probably want a buffer if it parses raw data, so you can just pass it the mmap result.

Here is an excellent example of usage

http://www.cs.purdue.edu/homes/fahmy/cs503/mmap.txt

0

精彩评论

暂无评论...
验证码 换一张
取 消