473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

about fwrite( )

how to use fwrite( ) instead of fprintf( ) in this case? I want to generate
binary file.

FILE *fnew;
int i, intName;
double array[500];

fprintf(fnew, "%d\n", intName);
fprintf(fnew, " %f", array[i]);
I know (I suppose) how to change the "intName" and "array[i]" using
fwrite( ) as follow:

fwrite(&intName, sizeof(int), 1, fnew);
fwrite(&array[i], sizeof(double), 1, fnew);

but how to hander the "\n" and " " using fwrite( )?
for example, how to handle this?

fprintf(fnew, " \n");
Nov 13 '05 #1
23 17797
On Mon, 13 Oct 2003 22:12:50 +0800, FrancisC wrote:
how to use fwrite( ) instead of fprintf( ) in this case? I want to generate
binary file.

FILE *fnew;
int i, intName;
double array[500];

fprintf(fnew, "%d\n", intName);
fprintf(fnew, " %f", array[i]);
I know (I suppose) how to change the "intName" and "array[i]" using
fwrite( ) as follow:

fwrite(&intName, sizeof(int), 1, fnew);
fwrite(&array[i], sizeof(double), 1, fnew);
fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);
but how to hander the "\n" and " " using fwrite( )?
for example, how to handle this?

fprintf(fnew, " \n");


Why would you want to? The data is binary, so people aren't going to read
it. Line formatting is pointless.

But, if you insist:

char s[] = " \n";
fwrite(s, sizeof s, 1, fnew);

Josh
Nov 13 '05 #2
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote:
how to use fwrite( ) instead of fprintf( ) in this case? I want to generate
binary file.
Generating binary files has nothing to do with whether you use fwrite()
or fprintf(), and everything with whether you fopen() your output stream
as "w" ("write - text mode") or "wb" ("write - binary mode").
FILE *fnew;
int i, intName;
double array[500];

fprintf(fnew, "%d\n", intName);


So, how _did_ you fopen() fnew?

Richard
Nov 13 '05 #3
Josh Sebastian wrote:

FILE *fnew;
int i, intName;
double array[500]; fwrite(&intName, sizeof(int), 1, fnew);
fwrite(&array[i], sizeof(double), 1, fnew);

fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


Sorry to bother you.
In:

fwrite(&intName, sizeof (intName), 1, fnew);
fwrite(&array[i], sizeof (array[i]), 1, fnew);

I understand why you changed the second one.
Is the first more for readability? Or for maintaince?
Nov 13 '05 #4
how to use fwrite( ) instead of fprintf( ) in this case? I want to generate binary file.

FILE *fnew;
int i, intName;
double array[500];

fprintf(fnew, "%d\n", intName);
fprintf(fnew, " %f", array[i]);
I know (I suppose) how to change the "intName" and "array[i]" using
fwrite( ) as follow:

fwrite(&intName, sizeof(int), 1, fnew);
fwrite(&array[i], sizeof(double), 1, fnew);
fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


why use sizeof (intName) and sizeof (array[i]) instead of sizeof(int) and
sizeof(double) ?
intName and array[] is set as int and double respectively
so are they both correct?
but how to hander the "\n" and " " using fwrite( )?
for example, how to handle this?

fprintf(fnew, " \n");


Why would you want to? The data is binary, so people aren't going to read
it. Line formatting is pointless.

But, if you insist:

char s[] = " \n";
fwrite(s, sizeof s, 1, fnew);


I want to maintain a file structure for later reading from the binary file.
So I think i need to, dont I?
Nov 13 '05 #5
how to use fwrite( ) instead of fprintf( ) in this case? I want to generate binary file.


Generating binary files has nothing to do with whether you use fwrite()
or fprintf(), and everything with whether you fopen() your output stream
as "w" ("write - text mode") or "wb" ("write - binary mode").
FILE *fnew;
int i, intName;
double array[500];

fprintf(fnew, "%d\n", intName);


So, how _did_ you fopen() fnew?

Richard


I use fnew = fopen(newFileName, "wb"), but I still can see the content
using notepad or other text editor, so i suppose it is ASCII, but I want to
generate binary file.
Nov 13 '05 #6
On Mon, 13 Oct 2003 23:18:21 +0800, FrancisC wrote:
> fwrite(&intName, sizeof(int), 1, fnew);
> fwrite(&array[i], sizeof(double), 1, fnew);


fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


why use sizeof (intName) and sizeof (array[i]) instead of sizeof(int) and
sizeof(double) ?
intName and array[] is set as int and double respectively
so are they both correct?


Yes, they are both correct, but what if you want to later change the type
of intName from, say, an int to a long? If you do it your way, you have to
search through the source and possibly change it where you shouldn't have.
With my way, you change it once (when it's defined) and that's it.

Also, for someone later reading your code, they have to look somewhere
else to find out whether or not intName is really an int, and if not what
were you trying to do? My way, you don't care what type it is... you're
just filling it with as many bytes as it can hold.
> but how to hander the "\n" and " " using fwrite( )?
> for example, how to handle this?
>
> fprintf(fnew, " \n");


Why would you want to? The data is binary, so people aren't going to read
it. Line formatting is pointless.

But, if you insist:

char s[] = " \n";
fwrite(s, sizeof s, 1, fnew);


I want to maintain a file structure for later reading from the binary file.
So I think i need to, dont I?


No, just count bytes. If you write out spaces, you'll just have to skip
over them when you read. All it does is make more work for yourself.

Josh
Nov 13 '05 #7
On Mon, 13 Oct 2003 23:22:48 +0800, FrancisC wrote:
I use fnew = fopen(newFileName, "wb"), but I still can see the content
using notepad or other text editor, so i suppose it is ASCII, but I want to
generate binary file.


Text data looks (for the most part) the same. The only thing that should
change is how numbers look.

Josh
Nov 13 '05 #8
FrancisC wrote:
[unattributed quotation]


I know (I suppose) how to change the "intName" and "array[i]" using
fwrite( ) as follow:

fwrite(&intName, sizeof(int), 1, fnew);
fwrite(&array[i], sizeof(double), 1, fnew);


fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


why use sizeof (intName) and sizeof (array[i]) instead of sizeof(int) and
sizeof(double) ?
intName and array[] is set as int and double respectively
so are they both correct?


The first form is correct provided that `intName' and
`array[i]' are an `int' and a `double', respectively. Are
they? You cannot tell by looking only at these lines; you
need to hunt for the variable declarations to be sure.

The second form is correct, even if `intName' is actually
a `long' or `short', and even if `array[i]' is a `float' or
a `long double'. It is correct even if the two variables are
`struct IntWrapper' and `struct FourDimensionalPoint'. You
can see immediately that it is correct, without rummaging
around elsewhere in the code.

The general principle is to avoid telling the compiler the
same thing twice, because you might contradict yourself by
mistake. You have already told the compiler what the types
of `intName' and `array' are, and the compiler remembers this
knowledge. The compiler's memory for this sort of fact is
more reliable than your own, so take advantage of it.

--
Er*********@sun.com
Nov 13 '05 #9
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote:
> fwrite(&intName, sizeof(int), 1, fnew);
> fwrite(&array[i], sizeof(double), 1, fnew);


fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


why use sizeof (intName) and sizeof (array[i]) instead of sizeof(int) and
sizeof(double) ?
intName and array[] is set as int and double respectively
so are they both correct?


Both are correct, but the latter versions are easier to maintain. Think
about what happens if you decide to change the type of intName or array:
in the former versions you have to adjust the operand of sizeof, the
latter will nicely 'auto-adjust'.
> but how to hander the "\n" and " " using fwrite( )?
> for example, how to handle this?
>
> fprintf(fnew, " \n");


Why would you want to? The data is binary, so people aren't going to read
it. Line formatting is pointless.

But, if you insist:

char s[] = " \n";
fwrite(s, sizeof s, 1, fnew);


I want to maintain a file structure for later reading from the binary file.
So I think i need to, dont I?


No, you don't have to. What you have to do is remember the file
structure ("field width") when you read the file.

BTW, if you want your data files to be reliably portable between
different OSs/implementations you want to stick to the text file
approach (as binary data representations tend to vary across different
systems). Eventually converting text files (if necessary at all) is not
a big deal compared to, for example, translation between different
floating point representations.

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #10
SomeDumbGuy <ab***@127.0.0.1> wrote:
Josh Sebastian wrote:

FILE *fnew;
int i, intName;
double array[500];fwrite(&intName, sizeof(int), 1, fnew);
fwrite(&array[i], sizeof(double), 1, fnew);

fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


Sorry to bother you.
In:

fwrite(&intName, sizeof (intName), 1, fnew);
fwrite(&array[i], sizeof (array[i]), 1, fnew);


Note: parantheses around these sizeof operands are redundant.
I understand why you changed the second one.
Is the first more for readability? Or for maintaince?


Both improve maintainability.

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #11
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote:
> how to use fwrite( ) instead of fprintf( ) in this case? I want togenerate > binary file.
Generating binary files has nothing to do with whether you use fwrite()
or fprintf(), and everything with whether you fopen() your output stream
as "w" ("write - text mode") or "wb" ("write - binary mode").
> FILE *fnew;
> int i, intName;
> double array[500];
>
> fprintf(fnew, "%d\n", intName);


So, how _did_ you fopen() fnew?

Richard


I use fnew = fopen(newFileName, "wb"), but I still can see the content
using notepad or other text editor, so i suppose it is ASCII,


Of course: you wrote text data to a file, what did you expect to see?
but I want to
generate binary file.


You already did; using fprintf, the binary data just happened to be
text. :-)

Regards
--
Irrwahn
(ir*******@freenet.de)
Nov 13 '05 #12
> how to use fwrite( ) instead of fprintf( ) in this case? I want to

generate
> binary file.

Generating binary files has nothing to do with whether you use fwrite()
or fprintf(), and everything with whether you fopen() your output stream as "w" ("write - text mode") or "wb" ("write - binary mode").

> FILE *fnew;
> int i, intName;
> double array[500];
>
> fprintf(fnew, "%d\n", intName);

So, how _did_ you fopen() fnew?

Richard


I use fnew = fopen(newFileName, "wb"), but I still can see the content
using notepad or other text editor, so i suppose it is ASCII,


Of course: you wrote text data to a file, what did you expect to see?
but I want to
generate binary file.


You already did; using fprintf, the binary data just happened to be
text. :-)


Thats why I do not want to use fprintf( ) but fwrite( ).
To make all the "things" binary, am I just need to use fwrite( ) all the
times but not using fprintf() ?
I want the filesize as small as possible and as easy for the computer to
read as possible
Nov 13 '05 #13
> fwrite(&intName, sizeof(int), 1, fnew);
> fwrite(&array[i], sizeof(double), 1, fnew);

fwrite(&intName, sizeof intName, 1, fnew);
fwrite(&array[i], sizeof array[i], 1, fnew);


why use sizeof (intName) and sizeof (array[i]) instead of sizeof(int) and
sizeof(double) ?
intName and array[] is set as int and double respectively
so are they both correct?


Both are correct, but the latter versions are easier to maintain. Think
about what happens if you decide to change the type of intName or array:
in the former versions you have to adjust the operand of sizeof, the
latter will nicely 'auto-adjust'.
> but how to hander the "\n" and " " using fwrite( )?
> for example, how to handle this?
>
> fprintf(fnew, " \n");

Why would you want to? The data is binary, so people aren't going to read it. Line formatting is pointless.

But, if you insist:

char s[] = " \n";
fwrite(s, sizeof s, 1, fnew);


I want to maintain a file structure for later reading from the binary file.So I think i need to, dont I?


No, you don't have to. What you have to do is remember the file
structure ("field width") when you read the file.

BTW, if you want your data files to be reliably portable between
different OSs/implementations you want to stick to the text file
approach (as binary data representations tend to vary across different
systems). Eventually converting text files (if necessary at all) is not
a big deal compared to, for example, translation between different
floating point representations.


thats mean if I want to store the file like this one (the integer is the no
of double no below):
3
100000.000000 200000.000000
300000.000000
4
100000.000000 200000.000000
300000.000000 400000.000000

in binary i should store like this with no space and new line?
3100000.000000200000.000000300000.0000004100000.00 0000200000.000000300000.00
0000400000.000000

when I want to read the file, I use the code below??

while ( !feof(fnew) )
{
fread(&intName, sizeof (intName), 1, fnew);
/*determine the integer value, intVal. (i do not know how to write this
code yet)*/
fread(&doubleNo, sizeof (doubleNo), intVal, fnew);
}



Nov 13 '05 #14


FrancisC wrote:
BTW, if you want your data files to be reliably portable between
different OSs/implementations you want to stick to the text file
approach (as binary data representations tend to vary across different
systems). Eventually converting text files (if necessary at all) is not
a big deal compared to, for example, translation between different
floating point representations.

thats mean if I want to store the file like this one (the integer is the no
of double no below):
3
100000.000000 200000.000000
300000.000000
4
100000.000000 200000.000000
300000.000000 400000.000000

in binary i should store like this with no space and new line?
3100000.000000200000.000000300000.0000004100000.00 0000200000.000000300000.00
0000400000.000000

when I want to read the file, I use the code below??

while ( !feof(fnew) )
{
fread(&intName, sizeof (intName), 1, fnew);
/*determine the integer value, intVal. (i do not know how to write this
code yet)*/
fread(&doubleNo, sizeof (doubleNo), intVal, fnew);
}


You have been warned that this it is not a portable to store these
values in a binary file. If you insist, here is how you might write
the code.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int count = 3, i;
double darray[3],dd;
FILE *fp;

if((fp = fopen("test.bin","wb")) != NULL)
{ /* Create and write the int and double values to binary file*/
if(1 != fwrite(&count,sizeof count,1,fp)) exit(EXIT_FAILURE);
for(i = 0;i < count;i++)
{
dd = i+1.0;
if(1 != fwrite(&dd,sizeof dd,1,fp)) exit(EXIT_FAILURE);
}
fclose(fp);
/* Read and Test the Binary File */
if((fp = fopen("test.bin","rb")) != NULL)
{ /* read the binary file */
if(1 != fread(&count, sizeof count,1,fp))
exit(EXIT_FAILURE);
for(i = 0;i < dd;i++)
if(1 != fread(&darray[i], sizeof darray[i],1,fp))
exit(EXIT_FAILURE);
fclose(fp);
}
}
/* print contents of binary file */
printf("Reading the binary file. there are %d \n"
"type double values in the file\nThery are:\n",count);
for(i = 0; i < count;i++)
printf("darray[%d] = %.2f\n",i,darray[i]);
return 0;
}

--
Al Bowers
Tampa, Fl USA
mailto: xa*@abowers.combase.com (remove the x)
http://www.geocities.com/abowers822/

Nov 13 '05 #15


FrancisC wrote:
BTW, if you want your data files to be reliably portable between
different OSs/implementations you want to stick to the text file
approach (as binary data representations tend to vary across different
systems). Eventually converting text files (if necessary at all) is not
a big deal compared to, for example, translation between different
floating point representations.
thats mean if I want to store the file like this one (the integer is the no
of double no below):
3
100000.000000 200000.000000
300000.000000
4
100000.000000 200000.000000
300000.000000 400000.000000

in binary i should store like this with no space and new line?
3100000.000000200000.000000300000.0000004100000.00 0000200000.000000300000.00
0000400000.000000


In binary the above looks completely different, since numbers are stored
in the memory representation at the file. That's what binary means: no
translation when writing to the file, no translation when reading from
the file.

when I want to read the file, I use the code below??

while ( !feof(fnew) )
{
fread(&intName, sizeof (intName), 1, fnew);
/*determine the integer value, intVal. (i do not know how to write this
code yet)*/
fread(&doubleNo, sizeof (doubleNo), intVal, fnew);
}


No.
For 2 reasons:
* You don't use feof to control the loop. That's not what it is ment for.
feof() is used *after* you finish reading to check why the read has stopped.
if it was because of eof, then you have read the whole file. If it was not
because of eof, then some error has occoured.

* It is always a good idea to store some count in the file (just as you have
done it in the text version), that will guide the read process.

int count;
double numbers[100];

/* somehow you have filled the array with the numbers
** and stored a count of how many entries in the array
** you have used in count
**
** now write to file
*/
fwrite( &count, sizeof( count ), 1, fnew );
fwrite( numbers, sizeof( numbers[0] ), count, fnew );
...

/*
** and read from file
*/
fread( &count, sizeof( count ), 1, fnew );
fread( numbers, sizeof( numbers[0] ), count, fnew );
of course error checking needs to be added (use the return values
of fwrite and fread), but basically thats it.

--
Karl Heinz Buchegger
kb******@gascad.at
Nov 13 '05 #16
On Mon, 13 Oct 2003 11:08:45 -0400,
Josh Sebastian <cu****@cox.net> wrote:


Why would you want to? The data is binary, so people aren't going to read
it. Line formatting is pointless.

But, if you insist:

char s[] = " \n";
fwrite(s, sizeof s, 1, fnew);

Doing that will also write the terminating \0 character to the file.
That is fine if that is what you intend to do.

Villy
Nov 13 '05 #17
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote:

[ Please do not snip attribution lines for quotes you leave in. While
you're at it, _do_ snip text you're not responding to. ]
but I want to generate binary file.
You already did; using fprintf, the binary data just happened to be
text. :-)


Thats why I do not want to use fprintf( ) but fwrite( ).
To make all the "things" binary, am I just need to use fwrite( ) all the
times but not using fprintf() ?


This makes no sense whatsoever. The data you have _is_ text. Writing it
using another function does not magically turn it into non-text. There
is _no_ difference between a byte written using fprintf() and the same
byte written using fwrite().
You seem to be rather confused as to what "binary data" actually is.
Have you considered the existence of the utility called "strings"? Have
you ever actually loaded a "binary" file into a text (or hex) viewer?
I want the filesize as small as possible and as easy for the computer to
read as possible


Those two requirements are mutually exclusive. To make the file as small
as possible, compress it. To make it easily readable, just output the
thing!

Richard
Nov 13 '05 #18
On Tue, 14 Oct 2003 08:31:45 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:

(lots of unattributed and untrimmed stuff)

Francis, some friendly advice: when responding to posts, please leave
the Attribution lines in (as above, the bit that says "FrancisC
wrote"), and trim your posts to remove irrelevant material.

Leaving in the attributions is important for people trying to follow a
thread, so you know who said which bit.
Trimming is important to ensure that posts to not become too long, and
relevant material appears in them.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #19
On Tue, 14 Oct 2003 08:09:40 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:
To make all the "things" binary, am I just need to use fwrite( ) all the
times but not using fprintf() ?


fwrite() dumps a block of memory to file. fprintf() prints formatted
data to a file, which might be text, or might not. Which do you want
to do?

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #20
"Mark McIntyre" <ma**********@spamcop.net> ???
news:34********************************@4ax.com ???...
On Tue, 14 Oct 2003 08:09:40 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:
To make all the "things" binary, am I just need to use fwrite( ) all the
times but not using fprintf() ?


fwrite() dumps a block of memory to file. fprintf() prints formatted
data to a file, which might be text, or might not. Which do you want
to do?


Actually, I want to write a program for Palm. And the data are loaded in the
memory of Palm.
Nov 13 '05 #21
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk...
"Mark McIntyre" <ma**********@spamcop.net> ???
news:34********************************@4ax.com ???...
On Tue, 14 Oct 2003 08:09:40 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:
To make all the "things" binary, am I just need to use fwrite( ) all thetimes but not using fprintf() ?
fwrite() dumps a block of memory to file. fprintf() prints formatted
data to a file, which might be text, or might not. Which do you want
to do?


Actually, I want to write a program for Palm. And the data are loaded in

the memory of Palm.


Well, why didn't you say so? :-)

IMO everything you need is here:
http://www.palmone.com/us/developers/

About halfway down the page, you'll find:

===========================
Create applications and add-ons for any Palm Powered device, including
licensee handhelds and communicators. This is also the place to learn about
the Palm OS platform and the strength of the growing Palm Economy.

Links:

Palm OS Developers
Getting Started
Platform Technologies
Tools & Downloads
Documentation
Support & Resources
Training
Certification
Developer Program
Resource Pavilion

===========================

BTW I found this in seconds with Google. :-)

If you decide you still want to use C to write
your programs, we can help you with the (standard)
C parts. The platform-specific parts which I'm
sure will also be needed are not topical here, but
you can get much help with that from that same site.

Oh, that'll be fifty cents for the directory assistance. :-)

HTH,
-Mike
Nov 13 '05 #22

"Mike Wahler" <mk******@mkwahler.net> ¦b¶l¥ó
news:Lc***************@newsread4.news.pas.earthlin k.net ¤¤¼¶¼g...
"FrancisC" <fr**********@hong-kong.crosswinds.net> wrote in message
news:bm***********@news.hgc.com.hk...
"Mark McIntyre" <ma**********@spamcop.net> ???
news:34********************************@4ax.com ???...
On Tue, 14 Oct 2003 08:09:40 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:

>To make all the "things" binary, am I just need to use fwrite( ) all the >times but not using fprintf() ?

fwrite() dumps a block of memory to file. fprintf() prints formatted
data to a file, which might be text, or might not. Which do you want
to do?
Actually, I want to write a program for Palm. And the data are loaded in

the
memory of Palm.


Well, why didn't you say so? :-)

IMO everything you need is here:
http://www.palmone.com/us/developers/

About halfway down the page, you'll find:

===========================
Create applications and add-ons for any Palm Powered device, including
licensee handhelds and communicators. This is also the place to learn

about the Palm OS platform and the strength of the growing Palm Economy.

Links:

Palm OS Developers
Getting Started
Platform Technologies
Tools & Downloads
Documentation
Support & Resources
Training
Certification
Developer Program
Resource Pavilion

===========================

BTW I found this in seconds with Google. :-)

If you decide you still want to use C to write
your programs, we can help you with the (standard)
C parts. The platform-specific parts which I'm
sure will also be needed are not topical here, but
you can get much help with that from that same site.

Oh, that'll be fifty cents for the directory assistance. :-)

HTH,
-Mike


Thank you :-)
All guys here are so great and helpful
Nov 13 '05 #23
On Tue, 14 Oct 2003 18:09:47 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:
"Mark McIntyre" <ma**********@spamcop.net> ???
news:34********************************@4ax.com ???...
On Tue, 14 Oct 2003 08:09:40 +0800, in comp.lang.c , "FrancisC"
<fr**********@hong-kong.crosswinds.net> wrote:
>To make all the "things" binary, am I just need to use fwrite( ) all the
>times but not using fprintf() ?


fwrite() dumps a block of memory to file. fprintf() prints formatted
data to a file, which might be text, or might not. Which do you want
to do?


Actually, I want to write a program for Palm. And the data are loaded in the
memory of Palm.


Yes, but C doesn't care about that. Presumably you've used a
palm-specific function to open a "file" from palm memory, then you
still have to ask "am I writing formatted data, or a chunk of memory?"

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Antoine Bloncourt | last post by:
Hello everybody Sorry to bother you but I have a problem writing datas into a file ... I want to make a backup of my MySQL database and put the result into a ..sql file. To do this, I use...
3
by: seia0106 | last post by:
Hello In the course of writing a program. I have to read and write a media file(*.avi/*.mpg/*.wav) to and from memory buffer. I can put the data(from a *.avi file)in buffer successfully but when...
5
by: mhk | last post by:
Hi , is there any way to merge three sorted arrays into a sorted file, without using 4th array. i guess 3 way merge sort is the only option but i dont know its algorithem. can anyone tell me...
15
by: Suraj Kurapati | last post by:
Hello, I'm having a rather strange bug with this code: for certain values of 'buf', a segmentation fault occurs when 'free(buf)' is followed by an 'fwrite()'. In the program output, there is no...
4
by: ibrahimover | last post by:
typedef struct{ char name; int no; }TAM; typedef struct{ char name; char ch; }HARF;
3
by: sumit1680 | last post by:
Hi everyone, I am using the below listed code The code is #include<stdio.h> #include<stdlib.h> #include<string.h>
2
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
12
by: hemant.gaur | last post by:
I have an application which writes huge number of bytes into the binary files which is just some marshalled data. int len = Data.size(); //arrary size for (int i = 0; i < len; ++i)...
25
by: Abubakar | last post by:
Hi, recently some C programmer told me that using fwrite/fopen functions are not efficient because the output that they do to the file is actually buffered and gets late in writing. Is that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.