>Paul Herring a �crit :
>>From: el Padre [mailto:[EMAIL PROTECTED]
>>
>>>Hi all,
>>>
>>>I need to read the whole content of a file in a string object.
>>
>>Why do you need to read the whole file in?
>
>Well I don't know if I really NEED to do that but what I want
>to do is find the most efficient (and not too complicated) way
>to find one occurence of a given string in the file so that I
>can find the number of pages of the pdf file.
>
>I read a part of the PDF format specifications (www.adobe.com)
>and figured out that I needed to find "/Pages" then "/Count"
>and the number of pages is following.
>
>how can I do that ?
>
>is it quicker to read line by line ?
It will certainly be easier, and less stress on any machine running your program on (say) a 1 gig file ;)
Is there a maximum length allowed for 'a line'? If so, then the easy way is:
allocate a buffer of max_length
while (more lines to read)
read a line into buffer
count occurances of '/Pages' and '/Count'
wend
If there is no maximum you need to do something similar to:
allocate a buffer of arbitrary_length
while (more data to read)
read arbitrary_length bytes/characters into buffer
count occurances of '/Pages' and '/Count'
if partial matches of '/Pages' and '/Count' at end of buffer
see if next few data complete the match
endif
wend
The reason for the extra bit is if you do two reads akin to the following:
......./Pag (End of first read)
es..... (Start of next read)
--
PJH
"...one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." - Robert Firth
Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12 8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272
Website : www.alderley.com Sales : [EMAIL PROTECTED] Service : [EMAIL PROTECTED]
This email and its contents are confidential and are solely for the use of the intended recipient. If you are not the original recipient you have received it in error and any use, dissemination, forwarding, printing or copying of this email is strictly prohibited. Should you receive this email in error please immediately notify [EMAIL PROTECTED]
This email has been scanned for viruses, however you should always scan emails with your own systems prior to opening.
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
