Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #8457 > unrolled thread
| Started by | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| First post | 2011-07-19 05:15 -0400 |
| Last post | 2011-07-19 09:42 +1200 |
| Articles | 11 — 5 participants |
Back to article view | Back to comp.lang.c
skipping bytes "Bill Cunningham" <nospam@nspam.invalid> - 2011-07-19 05:15 -0400
Re: skipping bytes John Gordon <gordon@panix.com> - 2011-07-18 21:35 +0000
Re: skipping bytes "Bill Cunningham" <nospam@nspam.invalid> - 2011-07-19 05:43 -0400
Re: skipping bytes blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-19 17:27 +0000
Re: skipping bytes Chad <cdalten@gmail.com> - 2011-07-19 12:09 -0700
Re: skipping bytes blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-19 21:34 +0000
Re: skipping bytes "Bill Cunningham" <nospam@nspam.invalid> - 2011-07-20 03:17 -0400
Re: skipping bytes blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-19 21:35 +0000
Re: skipping bytes "Bill Cunningham" <nospam@nspam.invalid> - 2011-07-20 07:01 -0400
Re: skipping bytes "Bill Cunningham" <nospam@nspam.invalid> - 2011-07-22 11:25 -0400
Re: skipping bytes Ian Collins <ian-news@hotmail.com> - 2011-07-19 09:42 +1200
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2011-07-19 05:15 -0400 |
| Subject | skipping bytes |
| Message-ID | <4e24a281$0$1929$bbae4d71@news.suddenlink.net> |
I want to take a 700MB file and skip evey 200MB, so I thought of this. long * space=malloc(sizeof(long)*500000); 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? Bill
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2011-07-18 21:35 +0000 |
| Message-ID | <j028v2$8ne$1@reader1.panix.com> |
| In reply to | #8457 |
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"
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2011-07-19 05:43 -0400 |
| Message-ID | <4e24a90b$0$8602$bbae4d71@news.suddenlink.net> |
| In reply to | #8458 |
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?")
[toc] | [prev] | [next] | [standalone]
| From | blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> |
|---|---|
| Date | 2011-07-19 17:27 +0000 |
| Message-ID | <98lt37FgvmU4@mid.individual.net> |
| In reply to | #8460 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Chad <cdalten@gmail.com> |
|---|---|
| Date | 2011-07-19 12:09 -0700 |
| Message-ID | <1abeef95-22ff-499a-b3c2-ab1a24e21c44@h25g2000prf.googlegroups.com> |
| In reply to | #8493 |
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
[toc] | [prev] | [next] | [standalone]
| From | blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> |
|---|---|
| Date | 2011-07-19 21:34 +0000 |
| Message-ID | <98mbitFse5U2@mid.individual.net> |
| In reply to | #8502 |
In article <1abeef95-22ff-499a-b3c2-ab1a24e21c44@h25g2000prf.googlegroups.com>, Chad <cdalten@gmail.com> wrote: > 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. > Au contraire -- but in the past it has been a lot clearer what Bill wanted to accomplish, even when the posted code didn't seem very promising as a way to accomplish the stated goal. -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2011-07-20 03:17 -0400 |
| Message-ID | <4e25d86a$0$1975$bbae4d71@news.suddenlink.net> |
| In reply to | #8493 |
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
[toc] | [prev] | [next] | [standalone]
| From | blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> |
|---|---|
| Date | 2011-07-19 21:35 +0000 |
| Message-ID | <98mbl9Fse5U3@mid.individual.net> |
| In reply to | #8503 |
In article <4e25d86a$0$1975$bbae4d71@news.suddenlink.net>, Bill Cunningham <nospam@nspam.invalid> wrote: > 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. Oh! Okay, well, that's not a task I'd have set myself, but this description is *almost* enough for me to imagine what the code might be like, and I guess I can sort of understand how it might seem like an interesting problem. (Depending on what kind of file it is, just replacing some of the data might or might not make it totally unreadable. But that may not matter to you.) One question you might ask yourself is where you're going to save the data you overwrite and want to put back later -- will it go in some separate file, or in some predetermined place in the original, or what? -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2011-07-20 07:01 -0400 |
| Message-ID | <4e260ccd$0$2574$bbae4d71@news.suddenlink.net> |
| In reply to | #8512 |
blmblm@myrealbox.com wrote:
> In article <4e25d86a$0$1975$bbae4d71@news.suddenlink.net>,
> Bill Cunningham <nospam@nspam.invalid> wrote:
>> 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.
>
> Oh! Okay, well, that's not a task I'd have set myself, but this
> description is *almost* enough for me to imagine what the code
> might be like, and I guess I can sort of understand how it might
> seem like an interesting problem. (Depending on what kind of file
> it is, just replacing some of the data might or might not make it
> totally unreadable. But that may not matter to you.)
>
> One question you might ask yourself is where you're going to
> save the data you overwrite and want to put back later -- will
> it go in some separate file, or in some predetermined place in
> the original, or what?
Exactly. I was thinking about saving it in another file. This would be
to complicted for me to simply put into main() and I would have to break it
down into function. I can almost imagine how to do it. I'm not bad with C
functions; the ones I use mostly but counting and reading and writing would
be more complicated for me.
Anyway. Interesting learning experience.
Bill
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2011-07-22 11:25 -0400 |
| Message-ID | <4e28edbe$0$1964$bbae4d71@news.suddenlink.net> |
| In reply to | #8512 |
blmblm@myrealbox.com wrote:
> Oh! Okay, well, that's not a task I'd have set myself, but this
> description is *almost* enough for me to imagine what the code
> might be like, and I guess I can sort of understand how it might
> seem like an interesting problem. (Depending on what kind of file
> it is, just replacing some of the data might or might not make it
> totally unreadable. But that may not matter to you.)
>
> One question you might ask yourself is where you're going to
> save the data you overwrite and want to put back later -- will
> it go in some separate file, or in some predetermined place in
> the original, or what?
I think I will store it at the end of the file. I will create a 32-bit
"streak" that goes down the middle of a file and save what is written to a
buffer and put it at the file's end. This would involve a struct wouldn't it
for a type of header or footer. That's a lot of data to be writing. I want
one function to read this, one to write, and main() in there.
Bill
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-07-19 09:42 +1200 |
| Message-ID | <98jnnoFl78U2@mid.individual.net> |
| In reply to | #8457 |
On 07/19/11 09:15 PM, Bill Cunningham wrote: > I want to take a 700MB file and skip evey 200MB, so I thought of this. > > long * space=malloc(sizeof(long)*500000); I thought of fish and chips, but it was equally irrelevant. Poor effort, 1/10. -- Ian Collins
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web