[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Re: skipping bytes

John Gordon

7/18/2011 9:36:00 PM

In <4e24a281$0$1929$bbae4d71@news.suddenlink.net> "Bill Cunningham" <nospam@nspam.invalid> writes:

> I want to take a 700MB file and skip evey 200MB, so I thought of this.

You mean you want to copy the 700MB file to another file, omitting
200MB chunks?

> long * space=malloc(sizeof(long)*500000);

There's no need to allocate that much space for a simple copy operation.
You can copy, say, 8K or 16K at a time without allocating a huge buffer.

> That would be good for code wouldn't it? Now how to tell where I am in the
> file. I have two choices. ftell() and fseek() or use f*pos() functions.
> Would anyone have any suggestions?

The f*pos() functions handle files which are too large for ftell/fseek,
and they also have special code to handle multibyte stream content.

If you don't care about those two concerns, then either functions will
work.

(By the way, I got this information by doing a Google search on the
phrase "what is the difference between ftell and fgetpos?")

--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

4 Answers

Bill Cunningham

7/19/2011 9:43:00 AM

0

John Gordon wrote:
> In <4e24a281$0$1929$bbae4d71@news.suddenlink.net> "Bill Cunningham"
> <nospam@nspam.invalid> writes:
>
>> I want to take a 700MB file and skip evey 200MB, so I thought of
>> this.
>
> You mean you want to copy the 700MB file to another file, omitting
> 200MB chunks?
>
>> long * space=malloc(sizeof(long)*500000);
>
> There's no need to allocate that much space for a simple copy
> operation.
> You can copy, say, 8K or 16K at a time without allocating a huge
> buffer.

I actually wanted to do something a little more difficult than just copy
the file. Every 200MB I want to save in a buffer about 8 bytes of data and
exchange 0x0000 for it. It doesn't have to be every 200M but it's such a
large file I thought of 200MB. Not using malloc() makes things so much
easier. It doesn't have to be exactly 8 bytes it could be 32. The important
thing is to correctly store the data read and save it correctly so it could
be put back.

>> That would be good for code wouldn't it? Now how to tell where I am
>> in the file. I have two choices. ftell() and fseek() or use f*pos()
>> functions. Would anyone have any suggestions?
>
> The f*pos() functions handle files which are too large for
> ftell/fseek,
> and they also have special code to handle multibyte stream content.
>
> If you don't care about those two concerns, then either functions will
> work.
>
> (By the way, I got this information by doing a Google search on the
> phrase "what is the difference between ftell and fgetpos?")


blmblm@myrealbox.com

7/19/2011 5:27:00 PM

0

In article <4e24a90b$0$8602$bbae4d71@news.suddenlink.net>,
Bill Cunningham <nospam@nspam.invalid> wrote:
> John Gordon wrote:
> > In <4e24a281$0$1929$bbae4d71@news.suddenlink.net> "Bill Cunningham"
> > <nospam@nspam.invalid> writes:
> >
> >> I want to take a 700MB file and skip evey 200MB, so I thought of
> >> this.
> >
> > You mean you want to copy the 700MB file to another file, omitting
> > 200MB chunks?
> >
> >> long * space=malloc(sizeof(long)*500000);
> >
> > There's no need to allocate that much space for a simple copy
> > operation.
> > You can copy, say, 8K or 16K at a time without allocating a huge
> > buffer.
>
> I actually wanted to do something a little more difficult than just copy
> the file. Every 200MB I want to save in a buffer about 8 bytes of data and
> exchange 0x0000 for it. It doesn't have to be every 200M but it's such a
> large file I thought of 200MB. Not using malloc() makes things so much
> easier. It doesn't have to be exactly 8 bytes it could be 32. The important
> thing is to correctly store the data read and save it correctly so it could
> be put back.

Do you have some end goal in mind, or are you doing this because it
somehow strikes you as an interesting or entertaining problem in its
own right? I can't make much sense of the above description and am
(mildly) curious.

[ snip ]

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.

Chad

7/19/2011 7:09:00 PM

0

On Jul 19, 10:27 am, blm...@myrealbox.com <blmblm.myreal...@gmail.com>
wrote:
> In article <4e24a90b$0$8602$bbae4...@news.suddenlink.net>,
>
>
>
>
>
> Bill Cunningham <nos...@nspam.invalid> wrote:
> > John Gordon wrote:
> > > In <4e24a281$0$1929$bbae4...@news.suddenlink.net> "Bill Cunningham"
> > > <nos...@nspam.invalid> writes:
>
> > >>     I want to take a 700MB file and skip evey 200MB, so I thought of
> > >> this.
>
> > > You mean you want to copy the 700MB file to another file, omitting
> > > 200MB chunks?
>
> > >> long * space=malloc(sizeof(long)*500000);
>
> > > There's no need to allocate that much space for a simple copy
> > > operation.
> > > You can copy, say, 8K or 16K at a time without allocating a huge
> > > buffer.
>
> >     I actually wanted to do something a little more difficult than just copy
> > the file. Every 200MB I want to save in a buffer about 8 bytes of data and
> > exchange 0x0000 for it. It doesn't have to be every 200M but it's such a
> > large file I thought of 200MB. Not using malloc() makes things so much
> > easier. It doesn't have to be exactly 8 bytes it could be 32. The important
> > thing is to correctly store the data read and save it correctly so it could
> > be put back.
>
> Do you have some end goal in mind, or are you doing this because it
> somehow strikes you as an interesting or entertaining problem in its
> own right?  I can't make much sense of the above description and am
> (mildly) curious.
>
> [ snip ]
>

You obviously haven't hung around this joint long enough.

Chad

Bill Cunningham

7/20/2011 7:18:00 AM

0

blmblm@myrealbox.com wrote:
> In article <4e24a90b$0$8602$bbae4d71@news.suddenlink.net>,
> Bill Cunningham <nospam@nspam.invalid> wrote:
>> John Gordon wrote:
>>> In <4e24a281$0$1929$bbae4d71@news.suddenlink.net> "Bill Cunningham"
>>> <nospam@nspam.invalid> writes:
>>>
>>>> I want to take a 700MB file and skip evey 200MB, so I thought
>>>> of this.
>>>
>>> You mean you want to copy the 700MB file to another file, omitting
>>> 200MB chunks?
>>>
>>>> long * space=malloc(sizeof(long)*500000);
>>>
>>> There's no need to allocate that much space for a simple copy
>>> operation.
>>> You can copy, say, 8K or 16K at a time without allocating a huge
>>> buffer.
>>
>> I actually wanted to do something a little more difficult than
>> just copy the file. Every 200MB I want to save in a buffer about 8
>> bytes of data and exchange 0x0000 for it. It doesn't have to be
>> every 200M but it's such a large file I thought of 200MB. Not using
>> malloc() makes things so much easier. It doesn't have to be exactly
>> 8 bytes it could be 32. The important thing is to correctly store
>> the data read and save it correctly so it could be put back.
>
> Do you have some end goal in mind, or are you doing this because it
> somehow strikes you as an interesting or entertaining problem in its
> own right? I can't make much sense of the above description and am
> (mildly) curious.

Please don't say "don't reinvent the wheel" it's all been done.
Everything is a learning experience. By punching "holes" in a file you make
it unreadable. By saving that information and reinserting it it becomes
readable again.

Bill