?
Solved

Output formatting

Posted on 2003-03-19
9
Medium Priority
?
203 Views
Last Modified: 2010-04-01
Hi,

I'm in my first year of a Computer Science class, and I'm working in a console program. I was wondering if there is anyway to have a carriage return without a line feed. By this I mean that it will move the cursor down one line from the current x-position. If there is anyway of doing this, it would be great appreciated if you would let me know!
0
Comment
Question by:Cyngus_X-1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Accepted Solution

by:
igor_sk earned 152 total points
ID: 8171622
Try printf("\v");
0
 
LVL 1

Expert Comment

by:igor_sk
ID: 8171626
Or in C++
cout << "\v";
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8171656
The conio.h function cprintf() will treat a newline ('\n') character as only a line feed and not as a carriage return. You can use it just like the c function printf, i.e.:

cprintf("First Line\nSecond Line");

or

int i = 3;
cprintf("x = %d",i);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8171659
Yeah, i tried \v already, it doesn't work for all compilers (for instance, Borland).
0
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8172079
Use the real value, not a string literal.

printf("%c", 0x13);  //10 or 13, i forget

brian
0
 
LVL 2

Expert Comment

by:DarthNemesis
ID: 8172125
Yep, same result as using \n or char(10). Simply prints a character (!! for 0x13, solid > for 0x10). The cprintf function is the only one that does it for me, but maybe the compiler Cygnus uses won't be as finicky.
0
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8172186
Yeah, I ran a test program, and got the same result.  It appears that the stream flushing is affecting the behavior.  If you build a string like "line1\rline2", and print that, you will see that \r probably works just fine.  DOS just isn't that friendly...

brian
0
 
LVL 12

Assisted Solution

by:Salte
Salte earned 148 total points
ID: 8173958
First off, if you want to move down and stay in current position, you want a 'line feed' or LF. The CR code or 'carriage return' will move the cursor to the beginning of current line.

The \r or CR is often used in a loop:

cout << '\r' << "Bytes left: " << setw(10) << nbytes << flush;

This will display the string "Bytes left: ...some number here..."

and will next time move the cursor back to beginning of line and display the same string but possibly with a new number, the result is that user see the number changing.

So your problem is that you would like to just output a '\n'. Your problem is that C treat a '\n' as a combination of '\r' followed by '\n' since C treat '\n' as the 'line break' code.

This leaves the option for \v and similar solutions. One obvious solution to your problem is to output a '\n' but make sure the system doesn't translate it to a CR LF combination first.

This is definitely a very system specific and you are therefore asking the question in the wrong forum. At the very least you should tell us which system you're on when you ask a system specific question.

I am very sure you don't want to output CR which is in a sense the opposite of what you want.

Alf
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9510604
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split points between igor_sk & Salte

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question