Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > add bytes to file

Reply
Thread Tools

add bytes to file

 
 
Bill Cunningham
Guest
Posts: n/a
 
      09-30-2012
Can someone show me how to add 3 or so bytes to the end of a file? I
have been studying and I'm thinking fseek() and fgetc() might be involved. I
can't seem to find any examples online unless I'm overlooking something.
Nothing in C that is.

Bill


 
Reply With Quote
 
 
 
 
Luuk
Guest
Posts: n/a
 
      09-30-2012
On 30-09-2012 21:40, Bill Cunningham wrote:
> Can someone show me how to add 3 or so bytes to the end of a file? I
> have been studying and I'm thinking fseek() and fgetc() might be involved. I
> can't seem to find any examples online unless I'm overlooking something.
> Nothing in C that is.
>
> Bill
>
>


if you know how to do some c programming,
than googling for:
c append to file
should solve your problem.


 
Reply With Quote
 
 
 
 
An tSin Gorm
Guest
Posts: n/a
 
      09-30-2012
In article <k4a768$t96$(E-Mail Removed)>,
"Bill Cunningham" <(E-Mail Removed)> wrote:

> Can someone show me how to add 3 or so bytes to the end of a file? I
> have been studying and I'm thinking fseek() and fgetc() might be involved. I
> can't seem to find any examples online unless I'm overlooking something.
> Nothing in C that is.


FILE *f = fopen(path, "r+");
fseek(f, 0, SEEK_END);
fputs("3 or so bytes", f);
fclose(f);

--
My name Indigo Montoya. \\ Annoying Usenet one post at a time.
You flamed my father. \' At least I can stay in character.
Prepare to be spanked. // When you look into the void,
Stop posting that! `/ the void looks into you, and fulfills you.
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-30-2012
An tSin Gorm wrote:
> In article <k4a768$t96$(E-Mail Removed)>,
> "Bill Cunningham" <(E-Mail Removed)> wrote:
>
>> Can someone show me how to add 3 or so bytes to the end of a
>> file? I have been studying and I'm thinking fseek() and fgetc()
>> might be involved. I can't seem to find any examples online unless
>> I'm overlooking something. Nothing in C that is.

>
> FILE *f = fopen(path, "r+");
> fseek(f, 0, SEEK_END);
> fputs("3 or so bytes", f);
> fclose(f);


Sorry I meant fputc but I guess fputs would work.

Bill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-30-2012
Luuk wrote:

> if you know how to do some c programming,
> than googling for:
> c append to file
> should solve your problem.


Ok but I just want to make sure I am not appending a string or any text
data. I want to append '\0' to the end and be able to reverse it. This is
for an encryption project.

Bill


 
Reply With Quote
 
An tSin Gorm
Guest
Posts: n/a
 
      09-30-2012
In article <k4a9do$3t7$(E-Mail Removed)>,
"Bill Cunningham" <(E-Mail Removed)> wrote:

> An tSin Gorm wrote:
> > In article <k4a768$t96$(E-Mail Removed)>,
> > "Bill Cunningham" <(E-Mail Removed)> wrote:
> >
> >> Can someone show me how to add 3 or so bytes to the end of a
> >> file? I have been studying and I'm thinking fseek() and fgetc()
> >> might be involved. I can't seem to find any examples online unless
> >> I'm overlooking something. Nothing in C that is.

> >
> > FILE *f = fopen(path, "r+");
> > fseek(f, 0, SEEK_END);
> > fputs("3 or so bytes", f);
> > fclose(f);

>
> Sorry I meant fputc but I guess fputs would work.
>
> Bill


Or fprintf or fwrite.

--
My name Indigo Montoya. \\ Annoying Usenet one post at a time.
You flamed my father. \' At least I can stay in character.
Prepare to be spanked. // When you look into the void,
Stop posting that! `/ the void looks into you, and fulfills you.
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-30-2012
An tSin Gorm wrote:
> In article <k4a9do$3t7$(E-Mail Removed)>,
> "Bill Cunningham" <(E-Mail Removed)> wrote:
>
>> An tSin Gorm wrote:
>>> In article <k4a768$t96$(E-Mail Removed)>,
>>> "Bill Cunningham" <(E-Mail Removed)> wrote:
>>>
>>>> Can someone show me how to add 3 or so bytes to the end of a
>>>> file? I have been studying and I'm thinking fseek() and fgetc()
>>>> might be involved. I can't seem to find any examples online unless
>>>> I'm overlooking something. Nothing in C that is.
>>>
>>> FILE *f = fopen(path, "r+");
>>> fseek(f, 0, SEEK_END);
>>> fputs("3 or so bytes", f);
>>> fclose(f);

>>
>> Sorry I meant fputc but I guess fputs would work.
>>
>> Bill

>
> Or fprintf or fwrite.


I'm kinda scratching my head here. Does you code append textual strings? I
want to append '\0' to the end of the file and be able to reverse that
process. Iprobably could go ahead and use a+ instead of r+ and skip the
fseek.

Bill


 
Reply With Quote
 
An tSin Gorm
Guest
Posts: n/a
 
      09-30-2012
In article <k4aa6c$5u3$(E-Mail Removed)>,
"Bill Cunningham" <(E-Mail Removed)> wrote:

> An tSin Gorm wrote:
> > In article <k4a9do$3t7$(E-Mail Removed)>,
> > "Bill Cunningham" <(E-Mail Removed)> wrote:
> >
> >> An tSin Gorm wrote:
> >>> In article <k4a768$t96$(E-Mail Removed)>,
> >>> "Bill Cunningham" <(E-Mail Removed)> wrote:
> >>>
> >>>> Can someone show me how to add 3 or so bytes to the end of a
> >>>> file? I have been studying and I'm thinking fseek() and fgetc()
> >>>> might be involved. I can't seem to find any examples online unless
> >>>> I'm overlooking something. Nothing in C that is.
> >>>
> >>> FILE *f = fopen(path, "r+");
> >>> fseek(f, 0, SEEK_END);
> >>> fputs("3 or so bytes", f);
> >>> fclose(f);
> >>
> >> Sorry I meant fputc but I guess fputs would work.
> >>
> >> Bill

> >
> > Or fprintf or fwrite.

>
> I'm kinda scratching my head here. Does you code append textual strings? I
> want to append '\0' to the end of the file and be able to reverse that
> process. Iprobably could go ahead and use a+ instead of r+ and skip the
> fseek.


I'm used to unix so text and binary files are the same; you can add "b" if
appropriate. Once the file is positionned, you can write the bytes with whatever
technique will write the bytes.

--
My name Indigo Montoya. \\ Annoying Usenet one post at a time.
You flamed my father. \' At least I can stay in character.
Prepare to be spanked. // When you look into the void,
Stop posting that! `/ the void looks into you, and fulfills you.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-30-2012
"Bill Cunningham" <(E-Mail Removed)> writes:

> Luuk wrote:
>
>> if you know how to do some c programming,
>> than googling for:
>> c append to file
>> should solve your problem.

>
> Ok but I just want to make sure I am not appending a string or any text
> data. I want to append '\0' to the end and be able to reverse it. This is
> for an encryption project.


If it relates to the programs you've been posting in
comp.unix.programmer this is the wrong way to pad the input so that it's
a multiple of 8 bytes in size.

--
Ben.
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-30-2012
An tSin Gorm wrote:
> In article <k4a9do$3t7$(E-Mail Removed)>,
> "Bill Cunningham" <(E-Mail Removed)> wrote:
>
>> An tSin Gorm wrote:
>>> In article <k4a768$t96$(E-Mail Removed)>,
>>> "Bill Cunningham" <(E-Mail Removed)> wrote:
>>>
>>>> Can someone show me how to add 3 or so bytes to the end of a
>>>> file? I have been studying and I'm thinking fseek() and fgetc()
>>>> might be involved. I can't seem to find any examples online unless
>>>> I'm overlooking something. Nothing in C that is.
>>>
>>> FILE *f = fopen(path, "r+");
>>> fseek(f, 0, SEEK_END);
>>> fputs("3 or so bytes", f);
>>> fclose(f);

>>
>> Sorry I meant fputc but I guess fputs would work.
>>
>> Bill

>
> Or fprintf or fwrite.


Hum. I see fputs takes a char *. I don't think that will be what I'm looking
for. And fputc only passes one int which would be as '\0' ascii equivalent I
think I might need fwrite().

Bill


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net Building Controls 0 07-29-2008 01:37 AM
Ratio of Bytes Delayed to Bytes Sent netproj Cisco 0 12-21-2005 08:08 PM
Why file containing 256 bytes is 257 bytes long? Yandos C++ 12 09-14-2005 11:53 PM
Private Bytes vs. # Bytes in all Heaps in Perfmon Jason Collins ASP .Net 3 02-18-2004 03:59 PM



Advertisments