473,385 Members | 1,901 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.

problem with carraige return...

86
now at the end of my out put i am putting a carriage return "\r" s that i can gain output on the same line but i am facing a problem...

such that...
Expand|Select|Wrap|Line Numbers
  1. cout<<"My name is Ayan \r";
  2. system("pause");
  3. cout<<"lalala";
  4.  
this make like this :

lalalae is Ayan

i.e all after "My name" remains in the second output....as if i am gettn a feedback from my previous output....how to tackle this...plez help...
May 12 '07 #1
12 1443
JosAH
11,448 Expert 8TB
now at the end of my out put i am putting a carriage return "\r" s that i can gain output on the same line but i am facing a problem...

such that...
Expand|Select|Wrap|Line Numbers
  1. cout<<"My name is Ayan \r";
  2. system("pause");
  3. cout<<"lalala";
  4.  
this make like this :

lalalae is Ayan

i.e all after "My name" remains in the second output....as if i am gettn a feedback from my previous output....how to tackle this...plez help...
Yep, nothing told your console to clear the rest of that line so previous output
remains visible. You could do it the quick and dirty way:
Expand|Select|Wrap|Line Numbers
  1. cout<<"My name is Ayan \r";
  2. system("pause"); 
  3. cout<<"lalala            "; // enough spaces
  4.  
kind regards,

Jos
May 12 '07 #2
ayan4u
86
Yep, nothing told your console to clear the rest of that line so previous output
remains visible. You could do it the quick and dirty way:
Expand|Select|Wrap|Line Numbers
  1. cout<<"My name is Ayan \r";
  2. system("pause"); 
  3. cout<<"lalala "; // enough spaces
  4.  
kind regards,

Jos

but this blocks my execution....which i dnt want...i thought of a process of getting the length my previous output and print space through out the output...then print my new output....i know its dirty but do you have any better alternative(s)...
May 12 '07 #3
Ganon11
3,652 Expert 2GB
You can use system("cls") to clear the entire screen of output, but not just the previous line. Will this work for you?
May 12 '07 #4
ayan4u
86
You can use system("cls") to clear the entire screen of output, but not just the previous line. Will this work for you?
i already experimented with that...but since its between a never ending loop...only to be ended by a keyboard input...

Expand|Select|Wrap|Line Numbers
  1.  
  2. while(!_kbhit())
  3. {
  4.  
  5. code...
  6.  
  7. }
  8.  
so if i use system("CLS") it takes much CPU time and screen flickers...and its too a OS dependent alternative and nasty one too..


any other better alternatives....
May 12 '07 #5
JosAH
11,448 Expert 8TB
but this blocks my execution....which i dnt want...i thought of a process of getting the length my previous output and print space through out the output...then print my new output....i know its dirty but do you have any better alternative(s)...
I don't understand what you mean by "but this blocks my execution". The little
hack I supplied works identical to what you wrote in your OP; it just prints
enough spaces to erase previous characters on that line. Nothing blocks.

kind regards,

Jos
May 12 '07 #6
ayan4u
86
I don't understand what you mean by "but this blocks my execution". The little
hack I supplied works identical to what you wrote in your OP; it just prints
enough spaces to erase previous characters on that line. Nothing blocks.

kind regards,

Jos
ok let me explain....and its very hard to do so without posting the full code...but i am trying to be as simple as i can

Expand|Select|Wrap|Line Numbers
  1. srand(time(0));
  2.  
  3. while(!_kbhit()
  4. {
  5. cout<<"The random number is :" <<rand()<<" \r";
  6.  
  7.  

now suppose for the first time the random number generated is 1000

so its prints ...

The random number is :1000

now the next random number be 3 but it will print

The random number is :3000

000 as a feedback from previous output...
now u proposed system(pause);

now if i design the code for minimum user interaction ur proposal defies it....as it will wait for a key press....and as a sideeffect my loop ends...as my loop is also waiting for a key press to terminate...

phewwww...well i think i presented my problem well...
May 12 '07 #7
JosAH
11,448 Expert 8TB
ok let me explain....and its very hard to do so without posting the full code...but i am trying to be as simple as i can

Expand|Select|Wrap|Line Numbers
  1. srand(time(0));
  2.  
  3. while(!_kbhit()
  4. {
  5. cout<<"The random number is :" <<rand()<<" \r";
  6.  
  7.  

now suppose for the first time the random number generated is 1000

so its prints ...

The random number is :1000

now the next random number be 3 but it will print

The random number is :3000

000 as a feedback from previous output...
now u proposed system(pause);

now if i design the code for minimum user interaction ur proposal defies it....as it will wait for a key press....and as a sideeffect my loop ends...as my loop is also waiting for a key press to terminate...

phewwww...well i think i presented my problem well...
Well, the system("pause") was your idea (see your original article) and I just
copied it. And when I wrote "enough spaces" that didn't imply "exactly enough"
spaces, maybe an additional, say, 50 spaces can do it (if the line lengths don't
differ more than 50 characters).

kind regards,

Jos
May 12 '07 #8
ayan4u
86
Well, the system("pause") was your idea (see your original article) and I just
copied it. And when I wrote "enough spaces" that didn't imply "exactly enough"
spaces, maybe an additional, say, 50 spaces can do it (if the line lengths don't
differ more than 50 characters).

kind regards,

Jos
hmm ....my original post confused you...ok ignore it and think about my last post...and the problem i showcased...
May 12 '07 #9
AdrianH
1,251 Expert 1GB
If you know the length of what you are outputing, then you should be able to determine how many spaces (if you want to use the exact number of spaces to clear the rest of the line). However, as Jos said, you could print out a bunch of excess spaces (the maximum you think you would require that would not cause you to move to the next line) to wipe any excess characters.

An alternative to '\r' is to use '\b' a bunch of times to backspace from the end to where you want to start writing. It requires more code and you to know how many characters to backspace over. In certain cases this may be slower or faster, depening on how many backspaces you do compaired with how many characters you would have to print out from the begining of the line. The more characters you output, the slower it will be.

Does this help?


Adrian
May 13 '07 #10
ayan4u
86
If you know the length of what you are outputing, then you should be able to determine how many spaces (if you want to use the exact number of spaces to clear the rest of the line). However, as Jos said, you could print out a bunch of excess spaces (the maximum you think you would require that would not cause you to move to the next line) to wipe any excess characters.

An alternative to '\r' is to use '\b' a bunch of times to backspace from the end to where you want to start writing. It requires more code and you to know how many characters to backspace over. In certain cases this may be slower or faster, depening on how many backspaces you do compaired with how many characters you would have to print out from the begining of the line. The more characters you output, the slower it will be.

Does this help?


Adrian
thnx Adrian about this /b idea sounds good and i will implement that...atleast its a bit better than the "filling up with spaces" technique for my case....

neways thanks to all of you for your coopeartion....i wll post if i face any difficulty regarding this any more....
May 13 '07 #11
JosAH
11,448 Expert 8TB
thnx Adrian about this /b idea sounds good and i will implement that...atleast its a bit better than the "filling up with spaces" technique for my case....

neways thanks to all of you for your coopeartion....i wll post if i face any difficulty regarding this any more....
Not all terminals wipe out a previous character when a '\b' is printed. You still
have to print spaces over the previous output then.

kind regards,

Jos
May 13 '07 #12
AdrianH
1,251 Expert 1GB
Not all terminals wipe out a previous character when a '\b' is printed. You still
have to print spaces over the previous output then.

kind regards,

Jos
Yeah, I wasn't meaning that the backspace would delete the character, it just moves the cursor to the left in all of the terminals I have ever used.


Adrian
May 13 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Fred Bloggs | last post by:
Hi, Can anybody help, I would like to prevent a carraige return from submitting a form, is there a way of doing this using a PHP script? Cheers, Sandy, new to PHP
3
by: Robert Oschler | last post by:
Hello, I am using the following function to try and strip both carraige returns and line feeds, ASCII 13 and 10 respectively, from a string. It doesn't seem to be working: x = filter(lambda...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
7
by: Tariq | last post by:
Hi, I am trying to do this bit using client side script in an asp page var x = "<%ServerVar%>"; The issue is if SerVar has carraige returns the Unterminates String Constant error is thrown...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
5
by: Jean-François Michaud | last post by:
Hello people, I am rather puzzled by this problem I am having with doubles here. The code seems to execute correctly for awhile and then all a sudden printfing out my doubles, I get -1.#IND00...
0
by: BlueTorpeedo | last post by:
Im writing a win32 C++ MFC console app that uses the CMimeMessage Class. I read text from a file, character by character, into a CString. I then put the CString into the email body via the addtext()...
2
by: Fred | last post by:
Hello, I am having a problem with a multiline string that I create from a byte array (xml file). I am using StringBuilder and Ecoding the string to ASCII (code below). / Upload the...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.