Author Topic: C++  (Read 4403 times)

zahc

  • friend
  • Senior Member
  • ***
  • Posts: 5,797
C++
« on: April 23, 2009, 04:38:11 PM »
I want to send text to an LCD panel. I can use an LCD library to send text and numbers (but not floats) to it. But I want to send it a double quotation mark. It's an ascii character, but I can't exactly do lcd.print("""); it's not syntactical. How can I encapsulate my " ?
Maybe a rare occurence, but then you only have to get murdered once to ruin your whole day.
--Tallpine

AZRedhawk44

  • friends
  • Senior Member
  • ***
  • Posts: 13,972
Re: C++
« Reply #1 on: April 23, 2009, 04:43:13 PM »
backslash.

\"

I think that should do it.

http://richardbowles.tripod.com/cpp/cpp15.htm
"But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist."
--Lysander Spooner

I reject your authoritah!

zahc

  • friend
  • Senior Member
  • ***
  • Posts: 5,797
Re: C++
« Reply #2 on: April 23, 2009, 04:57:48 PM »
Thanks. I thought about that, but in bash, the \ is usually used to ignore whatever comes after it.
« Last Edit: April 23, 2009, 06:06:10 PM by zahc »
Maybe a rare occurence, but then you only have to get murdered once to ruin your whole day.
--Tallpine

CNYCacher

  • friend
  • Senior Member
  • ***
  • Posts: 4,438
Re: C++
« Reply #3 on: April 23, 2009, 05:32:02 PM »
Thanks. I thought about that, bit in bash, the \ is usually used to ignore whatever comes after it.

Exactly

lcd.print("\"");

lcd.print('"'); will likely work also.

as will

lcd.print(34);

:)
On two occasions, I have been asked [by members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question.
Charles Babbage

Stetson

  • friends
  • Senior Member
  • ***
  • Posts: 1,094
Re: C++
« Reply #4 on: April 23, 2009, 06:47:09 PM »
I am so happy I don't have to program anything in C++ anymore.

I had enough problems in college.  All of this :
cd.print("\"");

lcd.print('"'); will likely work also.

as will

lcd.print(34);

went right through my eyes and out the back of my head.

Physics

  • ∇xE=-1/c·∂B/∂t, ∇·E=4πρ, ∇·B=0, ∇xB=1/c·∂E/∂t, F=q(E+v/cxB)
  • friend
  • Senior Member
  • ***
  • Posts: 1,315
Re: C++
« Reply #5 on: April 24, 2009, 12:54:12 AM »
Luckily I only ever need to use LabView.  The joys of experimental physics.   =D
In the world of science, there is physics.  Everything else is stamp collecting.  -Ernest Rutherford

zahc

  • friend
  • Senior Member
  • ***
  • Posts: 5,797
Re: C++
« Reply #6 on: April 24, 2009, 02:01:08 AM »
I hate labview.
Maybe a rare occurence, but then you only have to get murdered once to ruin your whole day.
--Tallpine

Perd Hapley

  • Superstar of the Internet
  • friend
  • Senior Member
  • ***
  • Posts: 61,425
  • My prepositions are on/in
Re: C++
« Reply #7 on: April 24, 2009, 02:45:03 AM »
C++ was the state of the art when I was taking comp sci courses 15 years ago.  Has nothing come along to replace it? 
"Doggies are angel babies!" -- my wife

Regolith

  • friend
  • Senior Member
  • ***
  • Posts: 6,171
Re: C++
« Reply #8 on: April 24, 2009, 03:00:39 AM »
C++ was the state of the art when I was taking comp sci courses 15 years ago.  Has nothing come along to replace it? 

Well, there's C#, but it isn't really that widespread.  C++ is still used when performance is required.

FWIW, C++ is the reason I switched my major from Computer Science to Multimedia.   :lol:

Or more precisely, the guy who taught C++ is the reason.  He was the type that TRIED to make you fail.  Average score on his tests were in the mid 40% range. Horrible teacher - he made you actively loath the subject at the end of his class. 

I still have my C++ reference manual laying around, though, along with my "C++ for dummies" book.  One of these days I'll get off my ass and teach it to myself...
The price of freedom is eternal vigilance. - Thomas Jefferson

Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves. - William Pitt the Younger

Perfectly symmetrical violence never solved anything. - Professor Hubert J. Farnsworth

Perd Hapley

  • Superstar of the Internet
  • friend
  • Senior Member
  • ***
  • Posts: 61,425
  • My prepositions are on/in
Re: C++
« Reply #9 on: April 24, 2009, 07:44:28 AM »
When I took programming classes at U of MO-Rolla, they were still teaching Fortran.  Or was it Cobal?  Anyway, I had a teacher that took off points for any mistake in a program, even a misspelling that would not affect how the program ran.  He docked me one point for "its" instead of "it's".  Thing is, it was the possessive "its" so it was spelled correctly. 
"Doggies are angel babies!" -- my wife

Fly320s

  • friend
  • Senior Member
  • ***
  • Posts: 14,415
  • Formerly, Arthur, King of the Britons
Re: C++
« Reply #10 on: April 24, 2009, 09:42:02 AM »
C++ = B- ?      ;)
Islamic sex dolls.  Do they blow themselves up?

cfabe

  • friend
  • Senior Member
  • ***
  • Posts: 513
Re: C++
« Reply #11 on: April 24, 2009, 09:44:02 AM »
The header file or documentation for the library should list the function declarations that exist for the .print function which will tell you what you can pass it. You've indicated it will accept a string or an integer. So you can do:

lcd.print("/""); as others have stated.

However lcd.print(34) may print out the integer 34 not the " character you want, depending on how the function's set up.

You illuded to wanting to print a float but not being able to. Since you can print a string, you can use the sprintf function to convert the float to a string. For example:

char buf[10];
float x = 1.234;
sprintf(buf, "%1.3f", x);

You could also do it using ftoa if that is implemented on your system.



makattak

  • Dark Lord of the Cis
  • friend
  • Senior Member
  • ***
  • Posts: 13,022
Re: C++
« Reply #12 on: April 24, 2009, 09:53:34 AM »
The header file or documentation for the library should list the function declarations that exist for the .print function which will tell you what you can pass it. You've indicated it will accept a string or an integer. So you can do:

lcd.print("/""); as others have stated.

However lcd.print(34) may print out the integer 34 not the " character you want, depending on how the function's set up.

You illuded to wanting to print a float but not being able to. Since you can print a string, you can use the sprintf function to convert the float to a string. For example:

char buf[10];
float x = 1.234;
sprintf(buf, "%1.3f", x);

You could also do it using ftoa if that is implemented on your system.




Wow, it's almost like you people are speaking English.

Also, alluded, not illuded.

Hey, I may not understand any of the rest of the post, but I can fix that!
« Last Edit: April 24, 2009, 11:29:48 AM by makattak »
I wish the Ring had never come to me. I wish none of this had happened.

So do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given to us. There are other forces at work in this world, Frodo, besides the will of evil. Bilbo was meant to find the Ring. In which case, you also were meant to have it. And that is an encouraging thought

Nightfall

  • friend
  • Senior Member
  • ***
  • Posts: 916
Re: C++
« Reply #13 on: April 24, 2009, 11:28:54 AM »
How can you NOT like C++? Heck, the main reason I'm working on a CompSci degree is because of how much I enjoyed the language.  =D
It is difficult if not impossible to reason a person out of a position they did not reason themselves into. - 230RN

BrokenPaw

  • friends
  • Senior Member
  • ***
  • Posts: 1,674
  • Sedit qvi timvit ne non svccederet.
    • ShadowGrove Interpath Ministry
Re: C++
« Reply #14 on: April 24, 2009, 11:47:08 AM »
C++ is still very much in use doing Real Work. 

There are people out there who want to use Java for everything (and many colleges are teaching Java as a result).  To be fair, Java's come a long way over its history, and it's less of a toy language than it used to be.  But there are still things it can't compete with C++ on.  It's also a dangerous language to teach on, because it does enough stuff for you that it breeds laziness.

C++ (and C) both have enough sharp edges and pointy bits that you learn how to be careful in ways that Java coders do not.

Right tool for the right job is what it comes down to; the system I work on uses C++ under the hood and behind the scenes, anywhere that we need high performance and/or a small footprint.  We use Java for user interfaces, because it's frankly better at them (and at making them cross-platform deployable).

I'm a C++ guy, who started out as a C guy.  I don't see C++ going away any time soon. 

-BP
Seek out wisdom in books, rare manuscripts, and cryptic poems if you will, but seek it also in simple stones and fragile herbs and in the cries of wild birds. Listen to the song of the wind and the roar of water if you would discover magic, for it is here that the old secrets are still preserved.

Marnoot

  • friend
  • Senior Member
  • ***
  • Posts: 2,965
Re: C++
« Reply #15 on: April 24, 2009, 11:48:14 AM »
We do all our new development in C# where I work. As mentioned C++ is much better for performance, but C#'s benefits outweigh performance for our particular use. Unfortunately I'm currently acting as a maintenance developer, so I spend most of my time with VB6.  =|

RevDisk

  • friend
  • Senior Member
  • ***
  • Posts: 12,633
    • RevDisk.net
Re: C++
« Reply #16 on: April 24, 2009, 11:57:05 AM »
C++ was the state of the art when I was taking comp sci courses 15 years ago.  Has nothing come along to replace it? 

No.  Except for maybe C, which obviously proceeded it.

There's TONS of other programming languages invented since C++.  Many of them are much better than C/C++ for niches, specific tasks or every day random tasks (perl!).  No single language however have come close to replacing it. 
"Rev, your picture is in my King James Bible, where Paul talks about "inventors of evil."  Yes, I know you'll take that as a compliment."  - Fistful, possibly highest compliment I've ever received.

zahc

  • friend
  • Senior Member
  • ***
  • Posts: 5,797
Re: C++
« Reply #17 on: April 24, 2009, 12:24:24 PM »
Quote
sprintf function to convert the float to a string.... You could also do it using ftoa if that is implemented on your system.


I'm actually programming a microcontroller using avr-gcc so I'm not sure what I have. I'm also a total programming noob. I actually wrote a function to round floats to a certain number of decimal places and display them (convert float to long, print that, print a period, multiply the original float by 10*<places>, mod<places>, print the remainder) but then I found that the LCD library actually will print floats with 2 decimal places, if you just naively pass them as if they were anything else. This is not in the docs at all and I don't know how it's implemented or if it rounds properly but it seems to be working and for display purposes I think I'll just let it do that.

Maybe a rare occurence, but then you only have to get murdered once to ruin your whole day.
--Tallpine

cfabe

  • friend
  • Senior Member
  • ***
  • Posts: 513
Re: C++
« Reply #18 on: April 24, 2009, 02:08:10 PM »
C and C++ are still very much in use in all sorts of embedded systems in many different markets. Chances are your DVD player, cell phone, the engine computer in your car all run code written and compiled at least partially in C. I have done software development on a number of performance based embedded systems and we typically used a mix of C, C++ and assembly depending on the performance requirements, cpu speed available, and program structure.

Regolith

  • friend
  • Senior Member
  • ***
  • Posts: 6,171
Re: C++
« Reply #19 on: April 24, 2009, 06:07:18 PM »
How can you NOT like C++? Heck, the main reason I'm working on a CompSci degree is because of how much I enjoyed the language.  =D

Like I said, it was more the professor than the language.  The guy was a brilliant programmer, but he had no business teaching. 

That, and I don't really have the temperament for sitting and coding all day.  I'm not quite detail-oriented enough, and that's not really a good trait in a programmer.
The price of freedom is eternal vigilance. - Thomas Jefferson

Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves. - William Pitt the Younger

Perfectly symmetrical violence never solved anything. - Professor Hubert J. Farnsworth

Brad Johnson

  • friend
  • Senior Member
  • ***
  • Posts: 18,083
  • Witty, charming, handsome, and completely insane.
Re: C++
« Reply #20 on: April 24, 2009, 07:15:45 PM »
Or was it Cobal? 

Cobol is the devil!

Brad
It's all about the pancakes, people.
"And he thought cops wouldn't chase... a STOLEN DONUT TRUCK???? That would be like Willie Nelson ignoring a pickup full of weed."
-HankB

RevDisk

  • friend
  • Senior Member
  • ***
  • Posts: 12,633
    • RevDisk.net
Re: C++
« Reply #21 on: April 25, 2009, 11:17:49 AM »
Cobol is the devil!

Brad

No, that grants the impression that Cobol has a degree of cleverness, flexibility or a sense of humor.   

No.  Cobol, my friend, is the IRS. 


;)
"Rev, your picture is in my King James Bible, where Paul talks about "inventors of evil."  Yes, I know you'll take that as a compliment."  - Fistful, possibly highest compliment I've ever received.

Regolith

  • friend
  • Senior Member
  • ***
  • Posts: 6,171
Re: C++
« Reply #22 on: April 25, 2009, 07:18:20 PM »
No, that grants the impression that Cobol has a degree of cleverness, flexibility or a sense of humor.   

No.  Cobol, my friend, is the IRS. 


;)

 :lol:
The price of freedom is eternal vigilance. - Thomas Jefferson

Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves. - William Pitt the Younger

Perfectly symmetrical violence never solved anything. - Professor Hubert J. Farnsworth

Perd Hapley

  • Superstar of the Internet
  • friend
  • Senior Member
  • ***
  • Posts: 61,425
  • My prepositions are on/in
Re: C++
« Reply #23 on: April 25, 2009, 10:33:41 PM »
Devil, IRS: there's a difference? 
"Doggies are angel babies!" -- my wife

Phyphor

  • friend
  • Senior Member
  • ***
  • Posts: 2,329
Re: C++
« Reply #24 on: April 25, 2009, 11:57:15 PM »
Yea, you can make deals with the Devil.
"You know what's messed-up about taxes?
You don't even pay taxes. They take tax.
You get your check, money gone.
That ain't a payment, that's a jack." - Chris Rock "Bigger and Blacker"
He slapped his rifle. "This is one of the best arguments for peace there is. Nobody wants to shoot if somebody is going to shoot back. " Callaghen, Callaghen, Louis La'mour