473,379 Members | 1,330 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,379 software developers and data experts.

char comparison help

HED
I am learning c++, and there is a lot that i dont know, so if this is
a stupid question, I am sorry. regardless, I am trying to get my
program to check and see if a char value is a certain value, and then
act appropriately. The compiler goes into fits when I do this, and if
I double click the error it opens ostream, and i figure that I really
have no business messing with that.

So, my code looks something like:

choice is a char and destination is a string. I think that the real
place that i have having trouble is in the comparing a char part of
the code. (basically I dont know how to do it and would like you to
tell me.) I have googled it, but I have a hard time finding code
snippets that explain how to do stuff.
if (choice = a)
destination = "someplace";
Thanks in advance for the help, if I need to post further
claification, please let me know.

--HED

Oct 11 '07 #1
4 7259
"HED" <me*************@hotmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
>I am learning c++, and there is a lot that i dont know, so if this is
a stupid question, I am sorry. regardless, I am trying to get my
program to check and see if a char value is a certain value, and then
act appropriately. The compiler goes into fits when I do this, and if
I double click the error it opens ostream, and i figure that I really
have no business messing with that.

So, my code looks something like:

choice is a char and destination is a string. I think that the real
place that i have having trouble is in the comparing a char part of
the code. (basically I dont know how to do it and would like you to
tell me.) I have googled it, but I have a hard time finding code
snippets that explain how to do stuff.
if (choice = a)
destination = "someplace";
Thanks in advance for the help, if I need to post further
claification, please let me know.

--HED
= is the assignment operator.

== is the comparison operator.

a look like a variable name. To compare choice with the char a use:
if (choice == 'a')

--
Scott McPhillips [VC++ MVP]

Oct 11 '07 #2
HED wrote:
I am learning c++ ...
Thanks in advance for the help, if I need to post further
claification, please let me know.
choice = a ?

Maybe you mean

choice == 'a'

?

Unless you define the `a` you're going to get undefined identifier
errors and if you use `=` (assignment) instead of `==` (equality
compare) you're probably not going to get behaviour you want.
Oct 11 '07 #3
HED wrote:
I am learning c++, and there is a lot that i dont know, so if this is
a stupid question, I am sorry. regardless, I am trying to get my
program to check and see if a char value is a certain value, and then
act appropriately. The compiler goes into fits when I do this, and if
I double click the error it opens ostream, and i figure that I really
have no business messing with that.

So, my code looks something like:

choice is a char and destination is a string. I think that the real
place that i have having trouble is in the comparing a char part of
the code. (basically I dont know how to do it and would like you to
tell me.) I have googled it, but I have a hard time finding code
snippets that explain how to do stuff.
if (choice = a)
Typo. Make that:

if ( choice == a )
^^
destination = "someplace";
Thanks in advance for the help, if I need to post further
claification, please let me know.
The comparison operators are

== equal
!= not equal
< less
<= less or equal (aka. not greater)
greater
= greater or equal (aka. not less)
You need to distinguish them from the assignment operators

= assignment
<<= shift in place
>>= shift in place

Best

Kai-Uwe Bux

Oct 11 '07 #4
HED
choice == 'a'
The comparison operators are

== equal
!= not equal
< less
<= less or equal (aka. not greater)
greater
= greater or equal (aka. not less)
You need to distinguish them from the assignment operators

= assignment
<<= shift in place
>>= shift in place
These are excatly (I think) what I am looking for. Thank you

Oct 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rob Smeets | last post by:
Hi all, I have the following problem: I have to revise a c++ dll. And i'm new to c++. I have to change a function, but i cannot change it's structure. I want to check the parameters and act...
2
by: Neil Zanella | last post by:
Hello, Consider the following program. There are two C style string stack variables and one C style string heap variable. The compiler may or may not optimize the space taken up by the two stack...
5
by: twkelsey | last post by:
Hi, My company has a scenario where we would like to change the data type of an existing primary key from an integer to a char, but we are concerned about the performance implications of doing...
3
by: Vishal Ladha | last post by:
Hi ! I have been experimenting with char * for a while now. I have two pieces of code : Code1 : ===== char *ptr = "hello";
20
by: Jacky Cheung | last post by:
Hi, I am developing a vCard application which have to support UTF-8. Does the UTF-8 in char* will crash the strlen, I mean does UTF-8 have some char which treat as NULL character in strlen? ...
11
by: Jason Curl | last post by:
Dear C people, C90 doesn't specify if 'char' is either 'signed char' or 'unsigned char' leaving it to the implementation of the compiler. Has this changed for C99, or is it still the same? ...
2
by: Henrik Goldman | last post by:
Hi, I'd like to use std::set to get a uniqueness between a set of (unsigned char *) with fixed known lengths. So I thought I would write my own class which holds this: class CUnique {
74
by: aruna.mysore | last post by:
Hi all, I have a simple definitioin in a C file something like this. main() { char a; ....... int k; }
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...

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.