Armed Polite Society

Main Forums => The Roundtable => Topic started by: zahc on April 23, 2009, 04:38:11 PM

Title: C++
Post by: zahc 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 " ?
Title: Re: C++
Post by: AZRedhawk44 on April 23, 2009, 04:43:13 PM
backslash.

\"

I think that should do it.

http://richardbowles.tripod.com/cpp/cpp15.htm
Title: Re: C++
Post by: zahc 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.
Title: Re: C++
Post by: CNYCacher 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);

:)
Title: Re: C++
Post by: Stetson 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.
Title: Re: C++
Post by: Physics on April 24, 2009, 12:54:12 AM
Luckily I only ever need to use LabView.  The joys of experimental physics.   =D
Title: Re: C++
Post by: zahc on April 24, 2009, 02:01:08 AM
I hate labview.
Title: Re: C++
Post by: Perd Hapley 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? 
Title: Re: C++
Post by: Regolith 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...
Title: Re: C++
Post by: Perd Hapley 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. 
Title: Re: C++
Post by: Fly320s on April 24, 2009, 09:42:02 AM
C++ = B- ?      ;)
Title: Re: C++
Post by: cfabe 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.


Title: Re: C++
Post by: makattak 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!
Title: Re: C++
Post by: Nightfall 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
Title: Re: C++
Post by: BrokenPaw 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
Title: Re: C++
Post by: Marnoot 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.  =|
Title: Re: C++
Post by: RevDisk 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. 
Title: Re: C++
Post by: zahc 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.

Title: Re: C++
Post by: cfabe 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.
Title: Re: C++
Post by: Regolith 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.
Title: Re: C++
Post by: Brad Johnson on April 24, 2009, 07:15:45 PM
Or was it Cobal? 

Cobol is the devil!

Brad
Title: Re: C++
Post by: RevDisk 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. 


;)
Title: Re: C++
Post by: Regolith 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:
Title: Re: C++
Post by: Perd Hapley on April 25, 2009, 10:33:41 PM
Devil, IRS: there's a difference? 
Title: Re: C++
Post by: Phyphor on April 25, 2009, 11:57:15 PM
Yea, you can make deals with the Devil.
Title: Re: C++
Post by: Perd Hapley on April 26, 2009, 01:21:22 AM
 =D