473,385 Members | 1,483 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,385 software developers and data experts.

basic c i/o and EOF

Below is the code ive written just to count the characters typed in. I
assumed EOF is -1, so if i type -1 and then press enter shouldnt the
program end? It orks if i put something like 'q' in the while loop to
end the loop.

what is up?

<code>

#include <stdio.h>

void main() {

long nc;

nc = 0;
while (getchar() != 'EOF') {
++nc;
}
printf("%ld\n", nc);

}

</code>

thanks
Dave

Nov 13 '05 #1
28 4548
"Dave" <no*****@noemail.com> skrev i meddelandet
news:bj**********@titan.btinternet.com...
Below is the code ive written just to count the characters typed in. I
assumed EOF is -1, so if i type -1 and then press enter shouldnt the
program end?


No, because when you type -1 it isn't stored as a character, but two
characters '-' and '1'. '-1' however is a single character, and those two
values doesn't match.

However, you could do a test yourself, and check for a series of letters.
Should be quite easy for you to do. I believe the theory is to put all the
input characters into an array, and check if the last two characters in the
array is equal to '-' and '1'.

--
Tim Cambrant
<tim at cambrant dot com>
Nov 13 '05 #2
On Thu, 11 Sep 2003 15:09:58 GMT, "Tim Cambrant" <ti*@cambrant.com.net> wrote:
"Dave" <no*****@noemail.com> skrev i meddelandet
news:bj**********@titan.btinternet.com...
Below is the code ive written just to count the characters typed in. I
assumed EOF is -1, so if i type -1 and then press enter shouldnt the
program end?


No, because when you type -1 it isn't stored as a character, but two
characters '-' and '1'. '-1' however is a single character, and those two
values doesn't match.

However, you could do a test yourself, and check for a series of letters.
Should be quite easy for you to do. I believe the theory is to put all the
input characters into an array, and check if the last two characters in the
array is equal to '-' and '1'.


Or better yet, if your platform supports it, enter the key or key combination
that signals end-of-input-data.

On MSDOS-based systems, this would be the ^Z key combination
On Unix-based systems, this would be what ever combination generates the 'eof'
signal (typically ^D, but check your stty settings to be sure).
--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
Nov 13 '05 #3
Dave <no*****@noemail.com> wrote:
Below is the code ive written just to count the characters typed in. I
assumed EOF is -1, so if i type -1 and then press enter shouldnt the
program end? Already addressed in the other replies.
It orks if i put something like 'q' in the while loop to
end the loop.

what is up?

<code>

#include <stdio.h>

void main() { int main( void ) {

long nc;

nc = 0;
while (getchar() != 'EOF') { ^^^^^
illegal character constant, just write EOF (it is defined in stdio.h)
++nc;
}
printf("%ld\n", nc);
return 0;}

</code> AFAIK it is implementation defined how to produce an EOF via the
keyboard (e.g. Ctr-Z, Ctrl-C, Ctrl-D, ... ).
thanks
Dave


Regards

Irrwahn
--
Close your eyes and press escape three times.
Nov 13 '05 #4
On Thu, 11 Sep 2003, Irrwahn Grausewitz wrote:
Dave <no*****@noemail.com> wrote:

long nc;

nc = 0;
while (getchar() != 'EOF') {

^^^^^
illegal character constant, just write EOF (it is defined in stdio.h)


It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)

--
au***@axis.com


Nov 13 '05 #5
In <ef********************************@4ax.com> Irrwahn Grausewitz <ir*****@freenet.de> writes:
Dave <no*****@noemail.com> wrote:
Below is the code ive written just to count the characters typed in. I
assumed EOF is -1, so if i type -1 and then press enter shouldnt the
program end?

Already addressed in the other replies.
It orks if i put something like 'q' in the while loop to
end the loop.

what is up?

<code>

#include <stdio.h>

void main() {

int main( void ) {

long nc;

nc = 0;
while (getchar() != 'EOF') {

^^^^^
illegal character constant, just write EOF (it is defined in stdio.h)


'EOF' is perfectly legal as a character constant, just not what the OP
needs in his program.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #6
Johan Aurér <au***@axis.com> wrote:
On Thu, 11 Sep 2003, Irrwahn Grausewitz wrote:
Dave <no*****@noemail.com> wrote:
>
> long nc;
>
> nc = 0;
> while (getchar() != 'EOF') { ^^^^^
illegal character constant, just write EOF (it is defined in stdio.h)


It's not "illegal," just implementation-defined.

Hmph, you're so right.
In fact, 'EOF' might
even equal EOF if you're lucky. :-)


I would call this bad luck, in that it would hide the fact that
one wrote unportable code. :-)

Irrwahn
--
Close your eyes and press escape three times.
Nov 13 '05 #7
Do you people know that code is taken from page 18
of The C programming language by kernigan & ritchie.
Nov 13 '05 #8
In article <bj**********@titan.btinternet.com>, amanayin wrote:
Do you people know that code is taken from page 18
of The C programming language by kernigan & ritchie.


Yes. It is similar to, but not the same as the code on that
page in that book.

--
Andreas Kähäri
Nov 13 '05 #9
Irrwahn Grausewitz <ir*****@freenet.de> writes:
Dave <no*****@noemail.com> wrote:
while (getchar() != 'EOF') {

^^^^^
illegal character constant, just write EOF (it is defined in stdio.h)


Not illegal, but its value is implementation-defined. It is
certainly not what the OP wants.
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
Nov 13 '05 #10
Dave <no*****@noemail.com> wrote in message news:<bj**********@titan.btinternet.com>...
Below is the code ive written just to count the characters typed in. I
assumed EOF is -1, so if i type -1 and then press enter shouldnt the
program end?
When you type -1 at the command line, you're entering a string of
characters, not a single integral value. What getchar() sees in the
input stream is '-', '1', not -1.

Entering an EOF at the command line varies from system to system.
Some may not allow it at all. You're better off using a specific
character like 'q' for an explicit quit command.

You could try Ctrl-D or Ctrl-Z, but don't expect them to work
everywhere.
It orks if i put something like 'q' in the while loop to
end the loop.

what is up?

<code>

#include <stdio.h>

void main() {
int main (void) {

long nc;

nc = 0;
while (getchar() != 'EOF') {
Lose the quotes around EOF.

while (getchar() != EOF) { ++nc;
}
printf("%ld\n", nc);

}

</code>

thanks
Dave

Nov 13 '05 #11
amanayin <ng******@netscape.net> writes:
Do you people know that code is taken from page 18
of The C programming language by kernigan & ritchie.


I am sure that K&R would not use 'EOF' to test for end-of-file,
because they know how to write C.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x1f6},*p=
b,x,i=24;for(;p+=!*p;*p/=4)switch(x=*p&3)case 0:{return 0;for(p--;i--;i--)case
2:{i++;if(1)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
Nov 13 '05 #12
amanayin <ng******@netscape.net> wrote:
Do you people know that code is taken from page 18
of The C programming language by kernigan & ritchie.

Let's see...

OP> #include <stdio.h>
OP>
OP> void main() {
OP>
OP> long nc;
OP>
OP> nc = 0;
OP> while (getchar() != 'EOF') {
OP> ++nc;
OP> }
OP> printf("%ld\n", nc);
OP> }

K&R> #include <stdio.h>
K&R>
K&R> main()
K&R> {
K&R> long nc;
K&R>
K&R> nc = 0;
K&R> while (getchar() != EOF)
K&R> ++nc;
K&R> printf("%ld\n", nc);
K&R> }

Notice the two differences?
Hint: one invokes UB in OP's code.

Irrwahn
--
Close your eyes and press escape three times.
Nov 13 '05 #13
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurér <au***@axis.com> wrote:
On Thu, 11 Sep 2003, Irrwahn Grausewitz wrote:
Dave <no*****@noemail.com> wrote:

long nc;

nc = 0;
while (getchar() != 'EOF') {

^^^^^
illegal character constant, just write EOF (it is defined in stdio.h)


It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)

No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.

--
Tschau/Bye
Herbert

eComStation 1.1 Deutsch Beta ist verügbar
Nov 13 '05 #14
In article <wmzsGguTDN6N-pn2-1wd4V82b3Onx@moon>,
The Real OS/2 Guy <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurér <au***@axis.com> wrote:
It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)


ITYM "not lucky".

No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.


Quoth n869 (6.4.4.4):
--------
Description

[#2] An integer character constant is a sequence of one or
^^^^^^
more multibyte characters enclosed in single-quotes, as in
^^^^
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.
--------

So 'abc' is no less a character constant than 'a'. It may or may not
correspond to an acceptable char value, but it's perfectly acceptable as a
source code construct. (And, just for if you're going to try to nitpick
on the 'may not correspond to an acceptable value', I'll point out that
'a' isn't a "character" either, only a character constant whose value
(of integer type) corresponds to the appropriate character.)
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Fortunately programmers who actually use those anomalous cases are few,
and getting fewer every time we catch up to one.
--David Thompson in comp.lang.c
Nov 13 '05 #15
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurér <au***@axis.com> wrote:
On Thu, 11 Sep 2003, Irrwahn Grausewitz wrote:
> Dave <no*****@noemail.com> wrote:
>
> >
> > long nc;
> >
> > nc = 0;
> > while (getchar() != 'EOF') {
> ^^^^^
> illegal character constant, just write EOF (it is defined in stdio.h)


It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)

No, 'abc' or 'EOF' or 'BAD' is NOT a character.

It's not a character, it's a (integer) character constant with
implementation-defined value.

From WG14/N843, section 6.4.4.4:

[...]

[#2] An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.

[...]

[#10] An integer character constant has type int. The value
of an integer character constant containing a single
character that maps to a member of the basic execution
character set is the numerical value of the representation
of the mapped character interpreted as an integer. The
value of an integer character constant containing more than
one character, or containing a character or escape sequence
not represented in the basic execution character set, is
implementation-defined. If an integer character constant
contains a single character or escape sequence, its value is
the one that results when an object with type char whose
value is that of the single character or escape sequence is
converted to type int.

<SNIP>

Irrwahn
--
I can't see it from here, but it looks good to me.
Nov 13 '05 #16
The Real OS/2 Guy wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurer <au***@axis.com> wrote:
It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)
No, 'abc' or 'EOF' or 'BAD' is NOT a character.


It is, however, a character constant.

The Standard says: "An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in 'x' or 'ab'."
A character is a
single char,


So 'a' is not a character, then?

(Hint: 'a' is of type int, not char.)

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #17
The Real OS/2 Guy wrote:
No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.

That must come as a shock to the guys who wrote the Standard:
[#2] An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.


Brian Rodenborn
Nov 13 '05 #18
Irrwahn Grausewitz <ir*****@freenet.de> wrote in message news:<f3********************************@4ax.com>. ..
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurér <au***@axis.com> wrote:
On Thu, 11 Sep 2003, Irrwahn Grausewitz wrote:

> Dave <no*****@noemail.com> wrote:
>
> >
> > long nc;
> >
> > nc = 0;
> > while (getchar() != 'EOF') {
> ^^^^^
> illegal character constant, just write EOF (it is defined in stdio.h)

It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)

No, 'abc' or 'EOF' or 'BAD' is NOT a character.

It's not a character, it's a (integer) character constant with
implementation-defined value.

From WG14/N843, section 6.4.4.4:

[...]

[#2] An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.

[...]

[#10] An integer character constant has type int. The value
of an integer character constant containing a single
character that maps to a member of the basic execution
character set is the numerical value of the representation
of the mapped character interpreted as an integer. The
value of an integer character constant containing more than
one character, or containing a character or escape sequence
not represented in the basic execution character set, is
implementation-defined. If an integer character constant
contains a single character or escape sequence, its value is
the one that results when an object with type char whose
value is that of the single character or escape sequence is
converted to type int.

<SNIP>

Irrwahn


When I use:

printf("%c\n", 'EOF');

It prints 'F', is it suppose to print that or am I invoking undefined behavior?
Nov 13 '05 #19
ne*****@tokyo.com (Mantorok Redgormor) wrote:
Irrwahn Grausewitz <ir*****@freenet.de> wrote in message news:<f3********************************@4ax.com>. ..
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote: <SNIP>
No, 'abc' or 'EOF' or 'BAD' is NOT a character.

It's not a character, it's a (integer) character constant with
implementation-defined value.

From WG14/N843, section 6.4.4.4:

[...]

[#2] An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.

[...]

[#10] An integer character constant has type int. The value
of an integer character constant containing a single
character that maps to a member of the basic execution
character set is the numerical value of the representation
of the mapped character interpreted as an integer. The <
value of an integer character constant containing more than <
one character, or containing a character or escape sequence <
not represented in the basic execution character set, is <
implementation-defined. If an integer character constant <
contains a single character or escape sequence, its value is
the one that results when an object with type char whose
value is that of the single character or escape sequence is
converted to type int.

<SNIP>


When I use:

printf("%c\n", 'EOF');

It prints 'F', is it suppose to print that or am I invoking undefined behavior?


It prints whatever the implementor intended. I've marked the relevant
section in the quote above with '<'s. You are not invoking any UB, but
the result is implementation-defined. Thus, you cannot use it in
portable code, but as long as you stick to one implementation you may
use it, for whatever purpose. If you want to find out what the value
of such a multi-character-constant is like, you have to consult the
documentation that comes with your compiler.

Regards

Irrwahn

--
I can't see it from here, but it looks good to me.
Nov 13 '05 #20
On Thu, 11 Sep 2003 21:00:07 UTC, dj******@csclub.uwaterloo.ca (Dave
Vandervies) wrote:
In article <wmzsGguTDN6N-pn2-1wd4V82b3Onx@moon>,
The Real OS/2 Guy <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurér <au***@axis.com> wrote:

It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)


ITYM "not lucky".

No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.


Quoth n869 (6.4.4.4):
--------
Description

[#2] An integer character constant is a sequence of one or
^^^^^^
more multibyte characters enclosed in single-quotes, as in
^^^^
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.
--------

So 'abc' is no less a character constant than 'a'. It may or may not
correspond to an acceptable char value, but it's perfectly acceptable as a
source code construct. (And, just for if you're going to try to nitpick
on the 'may not correspond to an acceptable value', I'll point out that
'a' isn't a "character" either, only a character constant whose value
(of integer type) corresponds to the appropriate character.)


I don't think that the OP uses a multibyte character sert. When he has
an single byte character set then the paragraph above is meaningless.

--
Tschau/Bye
Herbert

eComStation 1.1 Deutsch Beta ist verügbar
Nov 13 '05 #21
On Fri, 12 Sep 2003 02:15:04 UTC, ne*****@tokyo.com (Mantorok
Redgormor) wrote:
Irrwahn Grausewitz <ir*****@freenet.de> wrote in message news:<f3********************************@4ax.com>. ..
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurér <au***@axis.com> wrote:

> On Thu, 11 Sep 2003, Irrwahn Grausewitz wrote:
>
> > Dave <no*****@noemail.com> wrote:
> >
> > >
> > > long nc;
> > >
> > > nc = 0;
> > > while (getchar() != 'EOF') {
> > ^^^^^
> > illegal character constant, just write EOF (it is defined in stdio.h)
>
> It's not "illegal," just implementation-defined. In fact, 'EOF' might
> even equal EOF if you're lucky. :-)
>
No, 'abc' or 'EOF' or 'BAD' is NOT a character.

It's not a character, it's a (integer) character constant with
implementation-defined value.

From WG14/N843, section 6.4.4.4:

When I use:

printf("%c\n", 'EOF');

It prints 'F', is it suppose to print that or am I invoking undefined behavior?


I'm happy to have a compiler that will give a diagnostic when the
locale is not set to a multibyte character set, but uses a single byte
one.

--
Tschau/Bye
Herbert

eComStation 1.1 Deutsch Beta ist verügbar
Nov 13 '05 #22
On Thu, 11 Sep 2003 21:19:53 UTC, Richard Heathfield
<do******@address.co.uk.invalid> wrote:
The Real OS/2 Guy wrote:
On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurer <au***@axis.com> wrote:
It's not "illegal," just implementation-defined. In fact, 'EOF' might
even equal EOF if you're lucky. :-)
No, 'abc' or 'EOF' or 'BAD' is NOT a character.


It is, however, a character constant.

The Standard says: "An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in 'x' or 'ab'."


Does you know the difference between multibyte and single byte
chararer sets?
A character is a
single char,


So 'a' is not a character, then?


It is.
(Hint: 'a' is of type int, not char.)

It gets converted implicity to an int but it is none, else it were
impossible to assign it to an char without diagnostic.

--
Tschau/Bye
Herbert

eComStation 1.1 Deutsch Beta ist verügbar
Nov 13 '05 #23
On Thu, 11 Sep 2003 22:03:53 UTC, Default User
<fi********@company.com> wrote:
The Real OS/2 Guy wrote:
No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.

That must come as a shock to the guys who wrote the Standard:
[#2] An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.

Why? Read it carefully! Get be informed on the difference between
multibyte and single byte character sets.
A multibyte character set uses multiple bytes to show a single char. A
singe byte character set only one.

--
Tschau/Bye
Herbert

eComStation 1.1 Deutsch Beta ist verügbar
Nov 13 '05 #24
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote:

<SNIP>
I don't think that the OP uses a multibyte character sert. When he has
an single byte character set then the paragraph above is meaningless.


Which part of

[...] With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.

do you consider meaningless???
--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
Nov 13 '05 #25
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 21:19:53 UTC, Richard Heathfield
<do******@address.co.uk.invalid> wrote:
The Real OS/2 Guy wrote:
> On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurer <au***@axis.com> wrote:
>
>> It's not "illegal," just implementation-defined. In fact, 'EOF' might
>> even equal EOF if you're lucky. :-)
>>
> No, 'abc' or 'EOF' or 'BAD' is NOT a character.


It is, however, a character constant.

The Standard says: "An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in 'x' or 'ab'."


Does you know the difference between multibyte and single byte
chararer sets?


Do you know?

<SNIP>

--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
Nov 13 '05 #26
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 21:19:53 UTC, Richard Heathfield wrote:

(Hint: 'a' is of type int, not char.)

It gets converted implicity to an int but it is none, else it were
impossible to assign it to an char without diagnostic.


This is simply wrong. Character constants in C are of type integer.
Lookup the standard on 'character constants'.
--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
Nov 13 '05 #27
The Real OS/2 Guy wrote:
On Thu, 11 Sep 2003 21:19:53 UTC, Richard Heathfield
<do******@address.co.uk.invalid> wrote:
The Real OS/2 Guy wrote:
> On Thu, 11 Sep 2003 16:27:04 UTC, Johan Aurer <au***@axis.com> wrote:
>
>> It's not "illegal," just implementation-defined. In fact, 'EOF' might
>> even equal EOF if you're lucky. :-)
>>
> No, 'abc' or 'EOF' or 'BAD' is NOT a character.
It is, however, a character constant.

The Standard says: "An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in 'x' or 'ab'."


Does you know the difference between multibyte and single byte
chararer sets?


Yes.
> A character is a
> single char,


So 'a' is not a character, then?


It is.


Right, 'a' is a character, and 'a' is an int. Therefore, a character is not
a single char.
(Hint: 'a' is of type int, not char.)

It gets converted implicity to an int


No, it really really doesn't. It /is/ an int. AS USUAL, you sound very
confident but in fact you are utterly, utterly wrong. PLEASE understand
that you don't know as much about C as you thought you did. This is
something most of us go through when we start using this group; I know I
did, and lots of others here did too. But you seem to be slow to grasp
this. It's about time that you got a clue, and started to check your
opinions against an authoritative source before posting them.
but it is none, else it were
impossible to assign it to an char without diagnostic.


Nonsense.

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #28
On Sat, 13 Sep 2003 05:39:23 +0000 (UTC), in comp.lang.c , "The Real
OS/2 Guy" <os****@pc-rosenau.de> wrote:
On Thu, 11 Sep 2003 21:19:53 UTC, Richard Heathfield
<do******@address.co.uk.invalid> wrote:

So 'a' is not a character, then?
It is.

(Hint: 'a' is of type int, not char.)

It gets converted implicity to an int but it is none,


Er, no, a single character is of type int. The standard says so in
6.4.4.4.
else it were
impossible to assign it to an char without diagnostic.


Balderdash.

--
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>
Nov 13 '05 #29

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

Similar topics

7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
9
by: Malcolm | last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC interpreter. The question is, how is it most useful? At the moment I have a function int basic(const char *script,...
56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
14
by: luis | last post by:
Are basic types (int, long, ...) objetcs or not? I read that in C# all are objects including basic types, derived from Object class. Then in msdn documentation says that boxing converts basic...
3
by: sefe dery | last post by:
hi ng, i try to create a asp.net 1.0 website on windows server 2003(Servername: ServerX) with iis 6.0. PROBLEM: The user should login with his windows credentials in basic.aspx and...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
10
by: trippeer | last post by:
I have the source code to an old BASIC program that a friend of mine would like to run online. I am a beginner at JS, but I think that it would be a good choice for the project. My background is in...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
6
by: Simon Walsh | last post by:
I'm an Electronics student in college and I'm currently working on a project. I was given a circuit diagram for my project, from which I had to design a printed circuit board to be sent off and...
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...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.