How to print "\n" or '\0'

A

Army1987

Umesh said:
please help. thanks.

To print a newline, simplily use putchar('\n');
I can't imagine why you want to print a null character, but
putchar(0) should work.
 
J

Jens Thoms Toerring

Umesh said:
please help. thanks.

I would like to, but:

1) please put your question into the body of your posting,
2) please phrase your question in a way that it makes some
sense.
How to print "\n" or '\0'
doesn't.
Regards, Jens
 
O

osmium

"Umesh"
please help. thanks.

Are you purposely being dense? Haven't you been told to post your question
in the body of your message?

WRT the '\0'. That stand for null - note the lower case spelling - it's an
ordinary English word. Now look up null.

http://www.answers.com/null&r=67

Pay particular attention to definitions 3 and 4. Now how does one represent
nothing? Difficult isn't it? Perhaps you want to learn about the
hexadecimal representation of numbers. Look at the format specifier "%x".
 
U

Umesh

//how to print "\n" or '\0'

#include"stdio.h"
int main()
{
printf("\\n");
printf("\n");
printf("'\\0'");
return 0;
}
 
E

Eigenvector

Jens Thoms Toerring said:
I would like to, but:

1) please put your question into the body of your posting,
2) please phrase your question in a way that it makes some
sense.
How to print "\n" or '\0'
doesn't.
Regards, Jens

I'm amazed that only one person answered the question, while the rest of you
were overly concerned about specific structuring of the body of his post and
specific requirements for the wording.
 
I

Ian Collins

Eigenvector said:
I'm amazed that only one person answered the question, while the rest of you
were overly concerned about specific structuring of the body of his post and
specific requirements for the wording.
The OP is building quite a reputation for idiotic posts and ignoring advice.
 
R

Richard Heathfield

Eigenvector said:

I'm amazed that only one person answered the question, while the rest
of you were overly concerned about specific structuring of the body of
his post and specific requirements for the wording.

I'm astounded that anyone answered his question at all. I'd have thought
he'd be in everyone's killfiles by now.
 
C

Clever Monkey

Ian said:
The OP is building quite a reputation for idiotic posts and ignoring advice.
Not to mention that the one person answered only one of the many
possible interpretations of the question. Which is more helpful,
answering the wrong question, or asking for clarification?
 
P

Peter 'Shaggy' Haywood

Groovy hepcat Umesh was jivin' on 26 May 2007 09:25:29 -0700 in
comp.lang.c.
Re: How to print "\n" or '\0''s a cool scene! Dig it!
//how to print "\n" or '\0'

#include"stdio.h"

Now, I know you know better than that, Umesh. You must be trolling,
I think. The only explanation I can think of for your baffling
behaviour is that you are a troll.
That said, the only reason I'm responding to a troll is to encourage
others to ignore Umesh, and all trolls. Killfile the fool.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Peter said:
Groovy hepcat Umesh was jivin' on 26 May 2007 09:25:29 -0700 in
comp.lang.c.
Re: How to print "\n" or '\0''s a cool scene! Dig it!


Now, I know you know better than that, Umesh. You must be trolling,
I think. The only explanation I can think of for your baffling
behaviour is that you are a troll.
That said, the only reason I'm responding to a troll is to encourage
others to ignore Umesh, and all trolls. Killfile the fool.

#include "stdio.h" is allowed in standard C. When #include "..." does not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.
 
A

Army1987

Harald van D?k said:
#include "stdio.h" is allowed in standard C. When #include "..." does not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.

I don't think Peter referred to that. Umesh asked a question which
can be misunderstood very easily, then, after being told how to
print a newline or a null character[1], he answered his question
himself, showing that what he was trying to do was printing a
backslash followed by a lowercase n, or an apostrophe followed by
a backslash followed by the digit 0 followed by another apostrophe,
a question which could be asked much less ambiguously as "how can I
print a backslash?".

[1]Not always meaningless. For example, if you freopen()ed stdout
as a binary file (or if you are working on a Unix-like system where
there is no real difference between binary and text), and are
creating a PPM picture,
putchar(p.Red); putchar(p.Green); putchar(p.Blue);
should work even to put a black pixel.
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Army1987 said:
Harald van D?k said:
#include "stdio.h" is allowed in standard C. When #include "..." does not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.

I don't think Peter referred to that. Umesh asked a question which
can be misunderstood very easily, then, after being told how to
print a newline or a null character[1], he answered his question
himself, showing that what he was trying to do was printing a
backslash followed by a lowercase n, or an apostrophe followed by
a backslash followed by the digit 0 followed by another apostrophe,
a question which could be asked much less ambiguously as "how can I
print a backslash?".

What you are saying would also make sense, but I think he referred to the
#include style, because he snipped every other part of Umesh's code in his
reply.
 
A

Army1987

Harald van D?k said:
Army1987 said:
Harald van D?k said:
Peter 'Shaggy' Haywood wrote:
Groovy hepcat Umesh was jivin' on 26 May 2007 09:25:29 -0700 in
comp.lang.c.
Re: How to print "\n" or '\0''s a cool scene! Dig it!

//how to print "\n" or '\0'

#include"stdio.h"

Now, I know you know better than that, Umesh. You must be trolling,
I think. The only explanation I can think of for your baffling
behaviour is that you are a troll.
That said, the only reason I'm responding to a troll is to encourage
others to ignore Umesh, and all trolls. Killfile the fool.

#include "stdio.h" is allowed in standard C. When #include "..." does
not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.

I don't think Peter referred to that. Umesh asked a question which
can be misunderstood very easily, then, after being told how to
print a newline or a null character[1], he answered his question
himself, showing that what he was trying to do was printing a
backslash followed by a lowercase n, or an apostrophe followed by
a backslash followed by the digit 0 followed by another apostrophe,
a question which could be asked much less ambiguously as "how can I
print a backslash?".

What you are saying would also make sense, but I think he referred to the
#include style, because he snipped every other part of Umesh's code in his
reply.
Or he simplily arbitrarily snipped from that point onwards, considering he
did not snip the previous comment...
 
P

Peter 'Shaggy' Haywood

Groovy hepcat Harald van =?UTF-8?B?RMSzaw==?= was jivin' on Tue, 29
May 2007 18:43:15 +0200 in comp.lang.c.
Re: How to print "\n" or '\0''s a cool scene! Dig it!
#include "stdio.h" is allowed in standard C. When #include "..." does not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.

It's allowed (by the compiler). But that doesn't make it right. What
you say is true. However, if the compiler does find a header named
stdio.h before looking in the place it looks for <stdio.h>, then the
consequences depend on what's in that header.
In any case, the correct way to include the standard (or
implementation provided) stdio.h header is like so:

#include <stdio.h>

Anything else is the wrong way.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Peter said:
Groovy hepcat Harald van =?UTF-8?B?RMSzaw==?= was jivin' on Tue, 29
May 2007 18:43:15 +0200 in comp.lang.c.
Re: How to print "\n" or '\0''s a cool scene! Dig it!


It's allowed (by the compiler). But that doesn't make it right.

It's allowed by the standard, and that does make it right.
What
you say is true. However, if the compiler does find a header named
stdio.h before looking in the place it looks for <stdio.h>, then the
consequences depend on what's in that header.

Of course. And if the umesh did place a file named stdio.h in one of the
paths the compiler looks at only for #include "..." directives, presumably
he wanted it to be used, and then #include "stdio.h" is the only way to do
it.
In any case, the correct way to include the standard (or
implementation provided) stdio.h header is like so:

#include <stdio.h>

Anything else is the wrong way.

What's correct depends on what the C standard and the implementation's
documentation say is correct.
 
K

Keith Thompson

Harald van Dijk said:
Peter said:
Groovy hepcat Harald van =?UTF-8?B?RMSzaw==?= was jivin' on Tue, 29
May 2007 18:43:15 +0200 in comp.lang.c. [...]
#include "stdio.h" is allowed in standard C. When #include "..." does not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.

It's allowed (by the compiler). But that doesn't make it right.

It's allowed by the standard, and that does make it right.

No, it makes it legal; it may or may not be "right" in a particular
context.
Of course. And if the umesh did place a file named stdio.h in one of the
paths the compiler looks at only for #include "..." directives, presumably
he wanted it to be used, and then #include "stdio.h" is the only way to do
it.

If Umesh placed a file named stdio.h in some directory, it's probably
a mistake. This is a judgement based on the level of expertise Umesh
has displayed so far in this newsgroup.
What's correct depends on what the C standard and the implementation's
documentation say is correct.

And on the requirements in any particular case, unless you have a very
narrow definition of "correct". For example, the following program is
perfectly legal (in fact, I believe it's strictly conforming), but
it's not "correct".

#include <stdio.h>

#define SIX 1+5
#define NINE 8+1

int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Keith said:
Harald van Dijk said:
Peter said:
Groovy hepcat Harald van =?UTF-8?B?RMSzaw==?= was jivin' on Tue, 29
May 2007 18:43:15 +0200 in comp.lang.c. [...]
#include "stdio.h" is allowed in standard C. When #include "..." does
#not
pick up a file in the locations for user headers, it is replaced by the
compiler as if it read #include <...>.

It's allowed (by the compiler). But that doesn't make it right.

It's allowed by the standard, and that does make it right.

No, it makes it legal; it may or may not be "right" in a particular
context.

See below, I used "right" as "correct".
If Umesh placed a file named stdio.h in some directory, it's probably
a mistake. This is a judgement based on the level of expertise Umesh
has displayed so far in this newsgroup.

Fair enough.
And on the requirements in any particular case, unless you have a very
narrow definition of "correct". For example, the following program is
perfectly legal (in fact, I believe it's strictly conforming), but
it's not "correct".

#include <stdio.h>

#define SIX 1+5
#define NINE 8+1

int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}

Here's what I meant by correct:

If this is intended to print "6 * 9 = 54", the standard doesn't say that it
does (in fact, it says that it doesn't), so it is then not correct.

If this is intended to print "6 * 9 = 42", the standard says that it does,
so it is then correct.

I think this is not very different from what you mean, but please tell me if
I'm misunderstanding what you consider correct.
 
P

pete

Harald said:
Here's what I meant by correct:

If this is intended to print "6 * 9 = 54",
the standard doesn't say that it
does (in fact, it says that it doesn't),
so it is then not correct.

If this is intended to print "6 * 9 = 42",
the standard says that it does, so it is then correct.

I think this is not very different from what you mean,
but please tell me if
I'm misunderstanding what you consider correct.

The above shown code is a correct program.
The C99 standard says what a "correct program" is.

N869
4. Conformance
[#1] In this International Standard, ``shall'' is to be
interpreted as a requirement on an implementation or on a
program; conversely, ``shall not'' is to be interpreted as a
prohibition.
[#2] If a ``shall'' or ``shall not'' requirement that
appears outside of a constraint is violated, the behavior is
undefined. Undefined behavior is otherwise indicated in
this International Standard by the words ``undefined
behavior'' or by the omission of any explicit definition of
behavior. There is no difference in emphasis among these
three; they all describe ``behavior that is undefined''.
[#3] A program that is correct in all other aspects,
operating on correct data, containing unspecified behavior
shall be a correct program and act in accordance with
5.1.2.3.
 

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,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top