473,387 Members | 3,787 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,387 software developers and data experts.

Printf Issues

Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line. What in printf creates a new line,
as if it was endl; in cout?

For example:

printf ("Hello World!");
printf ("How are you?");

How would I make it skip a line to output:

Hello World!
How are you?

....rather than:

Hellow World!How are you?

Thanks.
Jul 22 '05 #1
4 1523
Ao the Unstoppable wrote:
printf ("Hello World!");
printf ("How are you?");

How would I make it skip a line to output:

Hello World!
How are you?

...rather than:

Hellow World!How are you?


Look up "escape codes" in the index of your least favorite tutorial.

\n

And it ain't a feature of printf, it's a feature of string and character
literals.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #2
On 29 Nov 2004 22:21:56 -0800, cy***********@gmail.com (Ao the
Unstoppable) wrote in comp.lang.c++:
Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line. What in printf creates a new line,
as if it was endl; in cout?

For example:

printf ("Hello World!"); printf ("Hello World!\n"); printf ("How are you?"); printf ("How are you?\n");
How would I make it skip a line to output:

Hello World!
How are you?

...rather than:

Hellow World!How are you?

Thanks.


The newline escape sequence '\n' works in C++ streams as well.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #3
Jack Klein <ja*******@spamcop.net> wrote in message news:<0s********************************@4ax.com>. ..
On 29 Nov 2004 22:21:56 -0800, cy***********@gmail.com (Ao the
Unstoppable) wrote in comp.lang.c++:
Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line. What in printf creates a new line,
as if it was endl; in cout?

For example:

printf ("Hello World!");

printf ("Hello World!\n");
printf ("How are you?");

printf ("How are you?\n");

How would I make it skip a line to output:

Hello World!
How are you?

...rather than:

Hellow World!How are you?

Thanks.


The newline escape sequence '\n' works in C++ streams as well.


you could use this:

printf ("Hello World!\nHow are you?");

'\n' is the newline character in c/c++
Jul 22 '05 #4
"Ao the Unstoppable" <cy***********@gmail.com> wrote in message
news:ba**************************@posting.google.c om...
Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
printf and then create a new line.


Why do you want to use printf instead of << ?
Jul 22 '05 #5

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

Similar topics

12
by: Minti | last post by:
Is std::cout slower than printf When we call printf e.g. in printf(20 format conversion specifications, 20 arguments); Is it faster than the std::cout << { 20 redirections to the output...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
9
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
6
by: David Mathog | last post by:
size_t varies from system to system. This occasionally leads to coding issues such as: (void) sprintf(msg,"length of buffer: %d",strlen(msg)); which worked fine on a 32 linux but triggered...
17
by: billposer | last post by:
The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which causes delimitation of integer groups as per the locale) is not in the C standard, and as applied to floats is not even in SUSv2....
19
by: v4vijayakumar | last post by:
why the following statement dumps the core(Segmentation fault)? printf("%s\n", __FILE__);
16
by: Gernot Frisch | last post by:
Hi, class MyString { char* m_data; public: MyString(const char* c) { m_data = new char; strcpy(m_data, c);
15
by: bryanvick | last post by:
I just started learning C, and wrote this small program to play around with the printf function in stdio.h. At the console, I am able to type input at the first 2 getchar() calls, but when I call...
15
by: singhraghvendra | last post by:
Hi I have a function as below void print(char* str) { printf(str); } now the user of the function can pass anything as the argument for
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:
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
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?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.