473,320 Members | 2,158 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,320 software developers and data experts.

How do I compare a charecter from a file with another character?

I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

Thanks,
Jonathan

Jul 22 '05 #1
4 1532
watch out for 'z' in if (ch == 'z')
Jonathan wrote:
I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

Thanks,
Jonathan


Jul 22 '05 #2
Jonathan wrote:
I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
If you want to compare a character with a character, you need to
use

if (ch == 'z')

"z" is a _string_literal_ and not a _character_.
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?


By reading the right books. What book are you reading that doesn't
explain the difference between 'z' and "z"?

V
Jul 22 '05 #3

"Jonathan" <tu**@alltel.net> wrote in message
news:Bp************@fe61.usenetserver.com...
I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?


Compare with a character.

if(ch == 'z')

-Mike
Jul 22 '05 #4

"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
watch out for 'z' in if (ch == 'z')
Jonathan wrote:
I've tried:

char ch;
ifstream fin("today.txt"); // open input file
while (fin.get(ch)) {
if (ch == "z")
cout << ch;}
fin.close();

but get the error

ISO C++ forbids comparison between pointer and integer

How do I work around this issue?

Thanks,
Jonathan


Thank you very much. That took care of the problem.

Jul 22 '05 #5

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

Similar topics

3
by: Matt | last post by:
if (123 > 33) will return true and if ("123" > 33) will return true So my question is, if the above behaviors are the same?? If string is a number, and compare with another number, it will...
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
9
by: Martoon | last post by:
I want to instantiate an STL map with my own compare function, and I want to pass a parameter to the compare function that will be stored and used for all comparisons in that map instance. As an...
4
by: Jim Langston | last post by:
Is there any builtin lowercase std::string compare? Right now I'm doing this: if ( _stricmp( AmmoTypeText.c_str(), "GunBullet" ) == 0 ) AmmoType = Item_Ammo_GunBullet; Is there anything the...
4
by: situ | last post by:
Hello all, i have a column in a table which stores tag lines which are usually less than 500 charecter. when we display the data through the browser some character display as "boxes" or junks....
2
by: ayan4u | last post by:
ok i have two problems... firstly in strict C enviornment is it possible to have a true dynamic charecter array with no predefined length...i mean to say... suppose.. char *array =NULL;...
2
by: phanimadhav | last post by:
Actually this is my tabledetails Table Name:Organisation Colums:Org_Id,org_Name,Org_Nationality Organisation namess is:Wipro,satyam,CTS,CMC,Infotech,Intel,Syentel,CISCO my requirement is if...
2
by: mail2ravi123 | last post by:
hi all, plz provide me a function that is used to compare wild char and as well as to compare * charecter and \ charecter in the string FYI if we want to compare a string for * charecter then...
35
by: hdsalbki | last post by:
hi everyone, I have below a small program to echo back what character the user types. It's working OK but prints a extra prompt between every character. what can I do? I'm new in C and my book is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.