473,324 Members | 2,400 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,324 software developers and data experts.

fread/fwrite

How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.

May 17 '07 #1
30 14231
empriser wrote:
How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.
None.

Don't you have documentation for these functions? Or man pages? Or
access to Google?

--
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

May 17 '07 #2
On 17 May 2007 00:52:29 -0700, empriser <xu********@gmail.comwrote:
>How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.
It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).
Remove del for email
May 17 '07 #3
On May 17, 8:25 pm, Barry Schwarz <schwa...@doezl.netwrote:
On 17 May 2007 00:52:29 -0700, empriser <xueyunl...@gmail.comwrote:
How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.

It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).

Remove del for email
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer, after last call
fread as if return 0.

Jul 5 '07 #4
empriser wrote:
On May 17, 8:25 pm, Barry Schwarz <schwa...@doezl.netwrote:
>On 17 May 2007 00:52:29 -0700, empriser <xueyunl...@gmail.comwrote:
>>How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.
It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).

Remove del for email

Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer, after last call
fread as if return 0.
fread returns the number of elements that were read and
stored in the buffer. If fread returns 10, it successfully
read and stored 10 elements. If fread returns 0, it read
and stored ... <wait for it... no elements.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jul 5 '07 #5
On Thu, 05 Jul 2007 05:00:26 -0000, empriser <xu********@gmail.com>
wrote:
>On May 17, 8:25 pm, Barry Schwarz <schwa...@doezl.netwrote:
>On 17 May 2007 00:52:29 -0700, empriser <xueyunl...@gmail.comwrote:
>How to use fread/fwrite copy a file.
When reach file's end, fread return 0, I don't konw how many bytes
in buf.

It depends on how code the fread. If you specify 1 block of n
characters and there is less than n left in the file, then it will
return 0. However, if you specify n blocks of 1 character each, then
it will return the number of blocks read (which will be exactly the
same as the number of characters read).

Remove del for email

Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer, after last call
fread as if return 0.
If you don't show your code, everything is just a guess. As long as
we are guessing, I guess that the number of bytes read is equal to the
square root of the address of fread (when cast to an unsigned short).
Remove del for email
Jul 6 '07 #6
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.

fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.
In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

....rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

--
Peter

Jul 6 '07 #7
OK I write a easy program to show it.
fread( buf, sizeof(buf), 1, rf );
fwrite( buf, sizeof(buf), 1, wf );

If I don't change to fread( buf, 1, sizeof(buf), rf ); how to copy a
file.

int main( int argc, char **argv )
{
int i;
char buf[1024];
FILE *rf, *wf;

rf = fopen( argv[1], "r" );
wf = fopen( argv[2], "w" );

i = fread( buf, sizeof(buf), 1, rf );
while( i 0 ){
fwrite( buf, sizeof(buf), 1, wf );
i = fread( buf, sizeof(buf), 1, rf );
}

fclose( rf );
fclose( wf );
return 0;
}

Jul 7 '07 #8
On Sat, 07 Jul 2007 03:04:46 -0000, empriser <xu********@gmail.com>
wrote:
>OK I write a easy program to show it.
fread( buf, sizeof(buf), 1, rf );
fwrite( buf, sizeof(buf), 1, wf );

If I don't change to fread( buf, 1, sizeof(buf), rf ); how to copy a
file.
By changing fread to fgetc and fwrite to fputc.

What is with the spate of "I've got this broken code I don't want to
change. How do I make it work?" messages. The only way to fix broken
code is to change it. It you don't change it, it remains broken.

If I insist on putting water in my gas tank, how do I get my car to
run?
>
int main( int argc, char **argv )
{
int i;
char buf[1024];
FILE *rf, *wf;

rf = fopen( argv[1], "r" );
wf = fopen( argv[2], "w" );

i = fread( buf, sizeof(buf), 1, rf );
while( i 0 ){
fwrite( buf, sizeof(buf), 1, wf );
i = fread( buf, sizeof(buf), 1, rf );
}

fclose( rf );
fclose( wf );
return 0;
}

Remove del for email
Jul 7 '07 #9
empriser wrote:
OK I write a easy program to show it.
fread( buf, sizeof(buf), 1, rf );
fwrite( buf, sizeof(buf), 1, wf );

If I don't change to fread( buf, 1, sizeof(buf), rf ); how to copy a
file.

int main( int argc, char **argv )
{
int i;
char buf[1024];
FILE *rf, *wf;

rf = fopen( argv[1], "r" );
wf = fopen( argv[2], "w" );

i = fread( buf, sizeof(buf), 1, rf );
while( i 0 ){
fwrite( buf, sizeof(buf), 1, wf );
i = fread( buf, sizeof(buf), 1, rf );
}

fclose( rf );
fclose( wf );
return 0;
}
Maybe this way..

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

int main(int argc, char *argv[]) {
FILE *in, *out;
char buf[100];
size_t size;

if ((in = fopen("cp.c", "rb")) == NULL)
puts("Can't open cp.c"), exit(EXIT_FAILURE);

if ((out = fopen("cp.x", "wb")) == NULL)
puts("Can't make cp.x"), exit(EXIT_FAILURE);

while ((size = fread(buf, 1, sizeof buf, in)) 0)
fwrite(buf, 1, size, out);

fclose(in);
fclose(out);
return 0;
}

Note that cp.c is the name of this source file.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jul 7 '07 #10
On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.
fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.

In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

--
Peter
Is size_t and all such stuffs portable in c? If not what to make it
so?
Guru Jois

Jul 8 '07 #11
Guru Jois wrote:
On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.
fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.
In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

Is size_t and all such stuffs portable in c? If not what to make it
so?
size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

Jul 8 '07 #12
Guru Jois wrote:
>
.... snip ...
>
Is size_t and all such stuffs portable in c? If not what to make
it so?
Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 8 '07 #13
On Jul 8, 4:03 am, CBFalconer <cbfalco...@yahoo.comwrote:
Guru Jois wrote:

... snip ...
Is size_t and all such stuffs portable in c? If not what to make
it so?

Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account fromhttp://www.teranews.com
How and where can I read to understand the perfect knowledge about C
standards.
Any docs/links to learn pure portable programs for C??? Docs
prefered..

Guru Jois

Jul 9 '07 #14
Guru Jois wrote:
On Jul 8, 4:03 am, CBFalconer <cbfalco...@yahoo.comwrote:
Guru Jois wrote:

... snip ...
Is size_t and all such stuffs portable in c? If not what to make
it so?
Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

How and where can I read to understand the perfect knowledge about C
standards.
Any docs/links to learn pure portable programs for C??? Docs
prefered..
As far as online tutorials are concerned I'll recommend Steve Summit's
one:

<http://www.eskimo.com/~scs/cclass/>

Also he maintains the very useful C FAQ:

<http://www.c-faq.com/>

There's also a clc "wiki":

<http://clc-wiki.net/>

Other resources include:

<http://www.lysator.liu.se/c/>
<http://www.dinkumware.com/manuals/>
<http://www-ccs.ucsd.edu/c/>
<http://www.open-std.org/jtc1/sc22/wg14/ - Site for the draft
Standard.
<http://www.knosof.co.uk/cbook/cbook.html>
<http://www.cpax.org.uk/prg/portable/c/index.php>

Jul 9 '07 #15
santosh said:

<snip>
As far as online tutorials are concerned I'll recommend Steve Summit's
one:

<http://www.eskimo.com/~scs/cclass/>
Please allow me to add the Tom Torfs tutorial URL:

<http://cprog.tomsweb.net/cintro.html>

Tom used to be a regular (and highly respected) comp.lang.c contributor.
Then, one day, he asked a question about C99, and it transpired that he
was writing a C99 preprocessor. He has not been seen since.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #16
On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
>Guru Jois wrote:
>On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
...
Yes my buffer size is n (n 1).
How do I know there are how many bytes in buffer,
after last call fread as if return 0.

fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.

In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.

Is size_t and all such stuffs portable in c? If not what to make it
so?

size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.
size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable
Jul 9 '07 #17
¬a\/b said:
On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
<snip>
>>size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

size_t is not portable because you all don't know the size it has
Nonsense. It is exactly sizeof(size_t) bytes in size.
only uint8_t uint16_t uint32_t, uint64_t are portable
My implementation has never heard of them, and gives me compilation
errors when I try to use them. So much for "portable".

But my implementation understands size_t just fine, thanks.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #18
¬a\/b wrote, On 09/07/07 07:42:
On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
>Guru Jois wrote:
>>On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
empriser wrote:
>...
>Yes my buffer size is n (n 1).
>How do I know there are how many bytes in buffer,
>after last call fread as if return 0.
fread returns the number of elements that were
read and stored in the buffer. If fread returns 10,
it successfully read and stored 10 elements. If
fread returns 0, it read and stored ... <wait for
it... no elements.
In other words, code as...

static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);

...rather than...

static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);

Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.
Is size_t and all such stuffs portable in c? If not what to make it
so?
size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable
Rubbish. There is no guarantee that the types you are suggesting are
available (even assuming C99) so they are less portable than size_t
which is *guaranteed* to exist. size_t is also the type returned by
fread (the function being called above), so whatever it is a variable of
type size_t is *guaranteed* to be large enough.
--
Flash Gordon
Jul 9 '07 #19
On Mon, 09 Jul 2007 08:19:40 +0100, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
>¬a\/b wrote, On 09/07/07 07:42:
>On Sun, 08 Jul 2007 02:36:55 -0700, santosh wrote:
>>Guru Jois wrote:
On Jul 5, 6:42 pm, Peter Nilsson <a...@acay.com.auwrote:
Eric Sosman <esos...@ieee-dot-org.invalidwrote:
>empriser wrote:
>>...
>>Yes my buffer size is n (n 1).
>>How do I know there are how many bytes in buffer,
>>after last call fread as if return 0.
> fread returns the number of elements that were
>read and stored in the buffer. If fread returns 10,
>it successfully read and stored 10 elements. If
>fread returns 0, it read and stored ... <wait for
>it... no elements.
In other words, code as...
>
static char buf[1024];
size_t r = fread(buf, 1, sizeof buf, fp);
>
...rather than...
>
static char buf[1024];
size_t r = fread(buf, sizeof buf, 1, fp);
>
Assuming no read errors, if there are 123 characters
left in the stream, the former will return 0 into r,
whereas the latter will return 123. Both calls will
read the same number of characters though.
Is size_t and all such stuffs portable in c? If not what to make it
so?
size_t is defined in the Standard, so it's certainly portable. New
users to C tend to have some confusion over using size_t objects with
printf and family. Generally using the lu format specifier with a cast
to the appropriate type is recommended. If you can, and want to, use
C99's additions the zu specifier is specifically there for size_t.

size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable

Rubbish. There is no guarantee that the types you are suggesting are
available (even assuming C99) so they are less portable than size_t
which is *guaranteed* to exist. size_t is also the type returned by
fread (the function being called above), so whatever it is a variable of
type size_t is *guaranteed* to be large enough.
each data definition that not fixed the size is unportable
each operation to data operand not well definited is unportable
Jul 9 '07 #20
¬a\/b said:

<snip>
each data definition that not fixed the size is unportable
Why?
each operation to data operand not well definited is unportable
size_t is well-defined.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #21
¬a/b wrote:
On Mon, 09 Jul 2007 08:19:40 +0100, Flash Gordon
<sp**@flash-gordon.me.ukwrote:
¬a\/b wrote, On 09/07/07 07:42:
<snip>
size_t is not portable because you all don't know the size it has
only uint8_t uint16_t uint32_t, uint64_t are portable
Rubbish. There is no guarantee that the types you are suggesting are
available (even assuming C99) so they are less portable than size_t
which is *guaranteed* to exist. size_t is also the type returned by
fread (the function being called above), so whatever it is a variable of
type size_t is *guaranteed* to be large enough.

each data definition that not fixed the size is unportable
How come then dynamically typed programming languages like Python and
Common Lisp are so portable and popular?
each operation to data operand not well definited is unportable
That's certainly true, but that's irrelevant to our discussion, since
size_t is well defined by the C Standard. What problems do you
specifically face when you use size_t?

Jul 9 '07 #22
On Mon, 09 Jul 2007 08:31:03 +0000, Richard Heathfield wrote:
>¬a\/b said:
>each data definition that not fixed the size is unportable

Why?
easy
>each operation to data operand not well definited is unportable

size_t is well-defined.
portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler

then you can argue how this program is portable
in the standard C language

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

int main(void)
{size_t z=0x2FFFF, h=0xFFFFFFFF;
z=z*z;
printf("Bits(size_t) 32 ?\n");

if(h<=0xFFFF||z<=h)
printf("No\n" );
else printf("Yes\n");

return 0;
}

because in each machine it could answer in a different way.
So what do you mean for the word "portable"? it is a meaningless word

in each machine where there are definitions like "size_t=number"
or where there are operations with size_t type variable =they are
not portable by definition (in each machine could be a different
result)

the problem is: size_t has different size each machine
but let it be size_t has 64 bits for all machine in the world
(or it is an memory only dipendent data type like a bignumber)

the problem could be for "*" function: can "*" function is the same in
all the machine and have the same result for the same operands?

the same for all other operators
the same for all UB and machine dipendent results
the same for all other "fixed all different size" data types
Jul 9 '07 #23
¬a\/b said:

<snip>
portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler

then you can argue how this program is portable
in the standard C language

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

int main(void)
{size_t z=0x2FFFF, h=0xFFFFFFFF;
No, this isn't portable, because C doesn't guarantee size_t can store
values as high as 0x2FFFF.

The fact that you can write a non-portable program using size_t does not
mean size_t is not portable.
So what do you mean for the word "portable"?
I mean that the program will achieve the same computational objective,
regardless of the implementation used to translate it.
it is a meaningless word
To you, maybe, but not to me.
in each machine where there are definitions like "size_t=number"
or where there are operations with size_t type variable =they are
not portable by definition (in each machine could be a different
result)
Two levers can be of different lengths, yet both can provide leverage,
and you can use either to shift a rock. Just as the concept of
"leverage" is portable across levers, so the concept of object size is
portable across implementations - and size_t is the type with which we
measure object sizes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 9 '07 #24
In article <31********************************@4ax.com>, ¬a\\/b <al@f.gwrote:
>portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler
>then you can argue how this program is portable
in the standard C language
[...]
>because in each machine it could answer in a different way.
"running the same way" does not mean the same as "will
produce the same answer". For example, a program to print
out the current calendar time might have the same code
on all the systems, but it is going to produce a different
answer when run on each one of them.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Jul 9 '07 #25
¬a/b wrote:
On Mon, 09 Jul 2007 08:31:03 +0000, Richard Heathfield wrote:

size_t is well-defined.

portable in my country means: i write a X language program;
that program run the same way in all machines
in the world that have a X language conform compiler

then you can argue how this program is portable
in the standard C language

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

int main(void)
{size_t z=0x2FFFF, h=0xFFFFFFFF;
You can't expect to portably store arbitrarily large values. size_t
can store values in the range of 0 ... SIZE_MAX. What's ill-defined
about this?
z=z*z;
Here you're performing an arithmetic calculation without checking for
the possibility of wrap-around. Again results might vary across
implementations, but this is not exclusive to size_t types.
printf("Bits(size_t) 32 ?\n");

if(h<=0xFFFF||z<=h)
You're comparing objects which might not hold the values intended for
them.
printf("No\n" );
else printf("Yes\n");

return 0;
}

because in each machine it could answer in a different way.
So what do you mean for the word "portable"? it is a meaningless word
And in what way is this exclusive to size_t. This is true for all of
C's numeric types. Each type's size and range are implementation
dependant except that certain minimum values are guaranteed by the
Standard. That's the price you'll have to pay for using an efficient,
statically typed language.

<snip>
the problem is: size_t has different size each machine
but let it be size_t has 64 bits for all machine in the world
(or it is an memory only dipendent data type like a bignumber)
If you want a language with dynamically sized types, there're plenty
of them floating around. C was not defined to be such a language. On
the other hand, if you stick to what's guaranteed by the Standard, you
_can_ achieve a very high level of source code portability. The
problem is, you want guarantees the Standard is not providing.

<snip>

Jul 9 '07 #26
On Mon, 09 Jul 2007 10:19:09 +0200, "¬a\\/b" <al@f.gwrote:
snip
>each data definition that not fixed the size is unportable
each operation to data operand not well definited is unportable
Well then, you must not use int either since there are a plethora of
16-bit and 32-bit implementations. You probably don't use char either
since we know sizeof(char) is 1 but we don't know anything about
CHAR_BIT other than it is at least 8.
Remove del for email
Jul 10 '07 #27
On Jul 8, 11:25 pm, santosh <santosh....@gmail.comwrote:
As far as online tutorials are concerned I'll recommend Steve Summit's
one:

<http://www.eskimo.com/~scs/cclass/>

Also he maintains the very useful C FAQ:

<http://www.c-faq.com/>

There's also a clc "wiki":

<http://clc-wiki.net/>

Other resources include:

<http://www.lysator.liu.se/c/>
<http://www.dinkumware.com/manuals/>
<http://www-ccs.ucsd.edu/c/>
<http://www.open-std.org/jtc1/sc22/wg14/ - Site for the draft
Standard.
<http://www.knosof.co.uk/cbook/cbook.html>
<http://www.cpax.org.uk/prg/portable/c/index.php>
Thanks Santhosh

Jul 10 '07 #28
On Jul 8, 11:41 pm, Richard Heathfield <r...@see.sig.invalidwrote:
santosh said:

<snip>
As far as online tutorials are concerned I'll recommend Steve Summit's
one:
<http://www.eskimo.com/~scs/cclass/>

Please allow me to add the Tom Torfs tutorial URL:

<http://cprog.tomsweb.net/cintro.html>

Tom used to be a regular (and highly respected) comp.lang.c contributor.
Then, one day, he asked a question about C99, and it transpired that he
was writing a C99 preprocessor. He has not been seen since.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Thanks to Richard too.

Jul 10 '07 #29
Richard Heathfield wrote:
¬a\/b said:

<snip>
>each data definition that not fixed the size is unportable

Why?
>each operation to data operand not well definited is unportable

size_t is well-defined.
Hint: ¬a\/b is a known troll.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 11 '07 #30
Guru Jois wrote:
CBFalconer <cbfalco...@yahoo.comwrote:
>Guru Jois wrote:

... snip ...
>>Is size_t and all such stuffs portable in c? If not what to make
it so?

Yes. That is, in part, why this newsgroup limits the topic to
STANDARD C, and considers references to system dependent things as
being off-topic. Read the standard.

How and where can I read to understand the perfect knowledge about
C standards. Any docs/links to learn pure portable programs for
C??? Docs prefered..
Please ensure you snip at least the sigs (the portion following the
"-- " marker). To reply to your query, try the URLs below as a
start.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/(C99 std)
<http://www.dinkumware.com/refxc.html (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>

--
Posted via a free Usenet account from http://www.teranews.com

Jul 11 '07 #31

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

Similar topics

8
by: Brady | last post by:
Hi, I'm having a problem reading and writing to a file. What I'm trying to do is read a file, modify the portion of the file that I just read, and then write the modified data back to the same...
2
by: Luc Holland | last post by:
Hey, I'm working on a program that reads a binary file. It's opened with ==== if ((f1=fopen(argv,"rb"))==NULL) { fprintf(stderr,"Error opening %s for reading . . .\n",argv); exit(2); } ====...
4
by: janssenssimon | last post by:
//de structure om de highscores in op de slagen typedef struct score{ char *naam; int veld; int score; struct score *volg; }HIGH; void toonhighscores(void)
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;
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
2
by: elisa | last post by:
Dear all, I have problems in writeing and reading a block of data (long array) with fread and fwrite. If I write and read an integer array, everything looks fine, but when I try long array, sth...
1
by: rohit deshpande | last post by:
i am writing a program in c,c++....... I want to read one file and write its contents using fread and fwrite functions. the program i hv written has no errors. but output file is not same as that of...
5
by: loudking | last post by:
Dear all, I encountered a problem with fread and fwrite. If I am going to copy a file using the same string, it will succeed char *file_content; struct stat buf; FILE *fp, *new_fp; ...
4
by: Highlander2nd | last post by:
Hello there. I'm Andrew Lucas, I'm a programmer for Half-Life. I've been working on stencil shadows lately, and I've been having problems saving mesh data for my models. When I store mesh data, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.