Removing numbers from a program.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 113
Reputation: zoner7 is an unknown quantity at this point 
Solved Threads: 4
zoner7 zoner7 is offline Offline
Junior Poster

Removing numbers from a program.

 
0
  #1
Dec 29th, 2007
I started using the tutorial "Teach Yourself C++ in 21 days" yesterday, and I absolutely love it's clarity. However, there is one thing that perturbs me about it. All of the code written in the code is numbered. This is a great feature until I want to try running the code for myself and end up having to 70 numbers. Is there anyway to create a function to remove these numbers? Perhaps I could turn each line into a string and delete the first spaces of every string... or something along those lines. Below is a section of code that appears in the tutorial.

1: // Demonstrates declaration of a class and
2: // definition of an object of the class,
3:
4: #include <iostream.h> // for cout
5:
6: class Cat // declare the class object
7: {
8: public: // members which follow are public
9: int itsAge;
10: int itsWeight;
11: };
12:
13:
14: void main()
15: {
16: Cat Frisky;
17: Frisky.itsAge = 5; // assign to the member variable
18: cout << "Frisky is a cat who is " ;
19: cout << Frisky.itsAge << " years old.\n";
20:
Last edited by zoner7; Dec 29th, 2007 at 2:39 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Removing numbers from a program.

 
0
  #2
Dec 29th, 2007
Yes, you could write a program that copies the sample files to a new file, removing the leading digits, colon and space from each line. This would be a good exercise. You would not necessarily need to handle each line as a string, just read characters until the first space, then copy characters to new file till newline encountered. Repeat till end of file.

Also, if you use Visual C++, in the edit window you can select columns of text by holding down the Alt key, then clicking and dragging the mouse. This makes manual removal of the numbering fairly quick and easy.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: Removing numbers from a program.

 
0
  #3
Dec 29th, 2007
thanks for the links...they are really useful...
but my problem is that i dont know what are commands to compile and run the cpp program..

ok see
steps are
1.save file in bin
2.run command prompt
3. type in cd c:\dev-cpp\bin
now i m in the same directory where the compiler and the program is saved...

now what next to compile my porgram named test.cpp

in java i know those commands they are
  1. cd c:\program files\java\jdk1.5\bin
  2. c:\program files\java\jdk1.5\bin> javac filename.java
  3. c:\program files\java\jdk1.5\bin> java filename this is a test program
...
output

the line THIS IS A TEST PROGRAM in the third line is a command line argument..

i wanna know the cpp equivalent for this..
Last edited by rajatC; Dec 29th, 2007 at 3:58 am.
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 113
Reputation: zoner7 is an unknown quantity at this point 
Solved Threads: 4
zoner7 zoner7 is offline Offline
Junior Poster

Re: Removing numbers from a program.

 
0
  #4
Dec 29th, 2007
DEV C++ has an integrated compiler; no commands are necessary to compile anything, unless of course you are simply interested. To compiler using the integrated compiler, look on the upper-left of the IDE at the second toolbar. The compiler button is the first button from the left.
To compiler using the command prompt, here's a link. The last post explains what you are looking for.
Last edited by zoner7; Dec 29th, 2007 at 2:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 113
Reputation: zoner7 is an unknown quantity at this point 
Solved Threads: 4
zoner7 zoner7 is offline Offline
Junior Poster

Re: Removing numbers from a program.

 
0
  #5
Dec 29th, 2007
Originally Posted by vmanes View Post
Yes, you could write a program that copies the sample files to a new file, removing the leading digits, colon and space from each line. This would be a good exercise. You would not necessarily need to handle each line as a string, just read characters until the first space, then copy characters to new file till newline encountered. Repeat till end of file.

Also, if you use Visual C++, in the edit window you can select columns of text by holding down the Alt key, then clicking and dragging the mouse. This makes manual removal of the numbering fairly quick and easy.
Well, I was able to remove the numbers quite easily using Visual C++, but you ignited my curiosity with that comment. How can I tell the program to read the characters?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Removing numbers from a program.

 
0
  #6
Dec 29th, 2007
Invent the program which read a file that contains those codes and write a new file with no number at the beginning of the line. To do this, you should this article:

http://www.daniweb.com/forums/thread6542.html
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Removing numbers from a program.

 
0
  #7
Dec 31st, 2007
thanks for the links...they are really useful...
I couldn't see any links posted in this thread before your post.
but my problem is that i dont know what are commands to compile and run the cpp program..

ok see
steps are
1.save file in bin
2.run command prompt
3. type in cd c:\dev-cpp\bin
now i m in the same directory where the compiler and the program is saved...

now what next to compile my porgram named test.cpp

in java i know those commands they are

(Toggle Plain Text)
cd c:\program files\java\jdk1.5\bin
c:\program files\java\jdk1.5\bin> javac filename.java
c:\program files\java\jdk1.5\bin> java filename this is a test programcd c:\program files\java\jdk1.5\bin
c:\program files\java\jdk1.5\bin> javac filename.java
c:\program files\java\jdk1.5\bin> java filename this is a test program
...
output

the line THIS IS A TEST PROGRAM in the third line is a command line argument..

i wanna know the cpp equivalent for this..
You've just hacked this thread for your own problem which is not at all related to what the OP of this thread is talking about. You should have started a new thread instead.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 109
Reputation: rajatC is an unknown quantity at this point 
Solved Threads: 7
rajatC's Avatar
rajatC rajatC is offline Offline
Junior Poster

Re: Removing numbers from a program.

 
0
  #8
Dec 31st, 2007
Originally Posted by Jishnu View Post
I couldn't see any links posted in this thread before your post.

You've just hacked this thread for your own problem which is not at all related to what the OP of this thread is talking about. You should have started a new thread instead.

actually that's the problem with my net connection..it's too slow and i got confused between a lots of tabs opened in my web browser...by mistake i posted it in this

it belong to the thread http://www.daniweb.com/forums/thread102784.html

sorry...it wont happen again...because i m going to change it...

*change my connection
Life is about being happy...
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Removing numbers from a program.

 
0
  #9
Dec 31st, 2007
sorry...
There's no need to be . I just mentioned it in case you had done it and you were not aware. Don't mind..
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC