Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   add bytes to file (http://www.velocityreviews.com/forums/t952875-add-bytes-to-file.html)

Bill Cunningham 09-30-2012 07:40 PM

add bytes to file
 
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



Luuk 09-30-2012 08:11 PM

Re: add bytes to file
 
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.



An tSin Gorm 09-30-2012 08:16 PM

Re: add bytes to file
 
In article <k4a768$t96$1@speranza.aioe.org>,
"Bill Cunningham" <nospam@nspam.invalid> 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.

Bill Cunningham 09-30-2012 08:18 PM

Re: add bytes to file
 
An tSin Gorm wrote:
> In article <k4a768$t96$1@speranza.aioe.org>,
> "Bill Cunningham" <nospam@nspam.invalid> 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



Bill Cunningham 09-30-2012 08:26 PM

Re: add bytes to file
 
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



An tSin Gorm 09-30-2012 08:27 PM

Re: add bytes to file
 
In article <k4a9do$3t7$1@speranza.aioe.org>,
"Bill Cunningham" <nospam@nspam.invalid> wrote:

> An tSin Gorm wrote:
> > In article <k4a768$t96$1@speranza.aioe.org>,
> > "Bill Cunningham" <nospam@nspam.invalid> 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.

Bill Cunningham 09-30-2012 08:31 PM

Re: add bytes to file
 
An tSin Gorm wrote:
> In article <k4a9do$3t7$1@speranza.aioe.org>,
> "Bill Cunningham" <nospam@nspam.invalid> wrote:
>
>> An tSin Gorm wrote:
>>> In article <k4a768$t96$1@speranza.aioe.org>,
>>> "Bill Cunningham" <nospam@nspam.invalid> 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



An tSin Gorm 09-30-2012 08:36 PM

Re: add bytes to file
 
In article <k4aa6c$5u3$1@speranza.aioe.org>,
"Bill Cunningham" <nospam@nspam.invalid> wrote:

> An tSin Gorm wrote:
> > In article <k4a9do$3t7$1@speranza.aioe.org>,
> > "Bill Cunningham" <nospam@nspam.invalid> wrote:
> >
> >> An tSin Gorm wrote:
> >>> In article <k4a768$t96$1@speranza.aioe.org>,
> >>> "Bill Cunningham" <nospam@nspam.invalid> 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.

Ben Bacarisse 09-30-2012 08:38 PM

Re: add bytes to file
 
"Bill Cunningham" <nospam@nspam.invalid> 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.

Bill Cunningham 09-30-2012 08:40 PM

Re: add bytes to file
 
An tSin Gorm wrote:
> In article <k4a9do$3t7$1@speranza.aioe.org>,
> "Bill Cunningham" <nospam@nspam.invalid> wrote:
>
>> An tSin Gorm wrote:
>>> In article <k4a768$t96$1@speranza.aioe.org>,
>>> "Bill Cunningham" <nospam@nspam.invalid> 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




All times are GMT. The time now is 01:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.