How to use EOF in C

K

Kelsey Bjarnason

Kelsey Bjarnason wrote:
Notice the other half of the expression?

Grr. Damn this being human thing sucks. :)
Anyway, regardless the code
is broken since if nch is not less than max, then additional input is
simply discarded.


An '\0' by itself is not a string.

Pass it to strlen, it'll work. Pass the results of whatever you've got
instead, it'll scream and die - if you're lucky.
 
R

Richard Heathfield

Flash Gordon said:

The standard even provides methods of expressing these things Malcolm
acknowledges as different.

char *sausages = NULL; /* No string */
char *sausages == ""; /* Empty string */
/* ITYM syntax error */
 
K

Keith Thompson

Kelsey Bjarnason said:
Pass it to strlen, it'll work.

strlen('\0') invokes undefined behavior.

I know that's not what you meant. If you pass the address of a
character with value '\0' to strlen(), it will return 0.
 
M

Malcolm McLean

Flash Gordon said:
Richard Heathfield wrote, On 12/07/07 21:10:

s/==/=/

char O=0; /* sausage */

char *sausages = 0-0-0-0-0-0-0; /* no string */
char *sausage = &O; /* empty string */
 
B

Ben Pfaff

Malcolm McLean said:
char O=0; /* sausage */

char *sausages = 0-0-0-0-0-0-0; /* no string */
char *sausage = &O; /* empty string */

char *confusing_sausage = &O-0-0-0-0-0-0-0; /* empty string */
 
R

Richard Bos

Malcolm McLean said:
char O=0; /* sausage */

char *sausages = 0-0-0-0-0-0-0; /* no string */
char *sausage = &O; /* empty string */

# Constraints
# 1 The operand of the unary & operator shall be either a function
# designator, the result of a [] or unary * operator, or an lvalue
# that designates an object that is not a bit-field and is not
# declared with the register storage-class specifier.

A literal 0 is not any of those, so &0 violates this constraint. Did you
perhaps mean "0" (or even &"0")?

Richard
 
K

Keith Thompson

Malcolm McLean said:
char O=0; /* sausage */

char *sausages = 0-0-0-0-0-0-0; /* no string */
char *sausage = &O; /* empty string */

# Constraints
# 1 The operand of the unary & operator shall be either a function
# designator, the result of a [] or unary * operator, or an lvalue
# that designates an object that is not a bit-field and is not
# declared with the register storage-class specifier.

A literal 0 is not any of those, so &0 violates this constraint. Did you
perhaps mean "0" (or even &"0")?

Get a better font, or copy-and-paste the code and try to compile it.
The initializer for 'sausage' is '&O', not '&0' (the letter, not the
digit); 'O' was declared three lines earlier as an object of type
char, initialized to zero.
 
K

Kelsey Bjarnason

strlen('\0') invokes undefined behavior.

True.
I know that's not what you meant. If you pass the address of a
character with value '\0' to strlen(), it will return 0.


In the context used. '\0' "works". In the general case, it doesn't, for
hopefully obvious reasons.
 
M

Malcolm McLean

Keith Thompson said:
Malcolm McLean said:
char O=0; /* sausage */

char *sausages = 0-0-0-0-0-0-0; /* no string */
char *sausage = &O; /* empty string */

# Constraints
# 1 The operand of the unary & operator shall be either a function
# designator, the result of a [] or unary * operator, or an lvalue
# that designates an object that is not a bit-field and is not
# declared with the register storage-class specifier.

A literal 0 is not any of those, so &0 violates this constraint. Did you
perhaps mean "0" (or even &"0")?

Get a better font, or copy-and-paste the code and try to compile it.
The initializer for 'sausage' is '&O', not '&0' (the letter, not the
digit); 'O' was declared three lines earlier as an object of type
char, initialized to zero.
It was a charred sausage.
 
R

Richard Bos

Malcolm McLean said:
Keith Thompson said:
char O=0; /* sausage */

char *sausages = 0-0-0-0-0-0-0; /* no string */
char *sausage = &O; /* empty string */

# Constraints
# 1 The operand of the unary & operator shall be either a function
# designator, the result of a [] or unary * operator, or an lvalue
# that designates an object that is not a bit-field and is not
# declared with the register storage-class specifier.

A literal 0 is not any of those, so &0 violates this constraint. Did you
perhaps mean "0" (or even &"0")?

Get a better font, or copy-and-paste the code and try to compile it.
The initializer for 'sausage' is '&O', not '&0' (the letter, not the
digit); 'O' was declared three lines earlier as an object of type
char, initialized to zero.

*Hangs head in shame*
It was a charred sausage.

*Groans*

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top