User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,772 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1472 | Replies: 3 | Solved
Reply
Join Date: Aug 2007
Posts: 66
Reputation: toko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
toko's Avatar
toko toko is offline Offline
Junior Poster in Training

Question comparing char with constant char

  #1  
Nov 30th, 2007
okay i am trying to compare a char thats a constant with a char that a person has inputed however this is as far as i have gotten and its not working.

#include <iostream>
using namespace std;

int main()
{
    char input[20];
    char correct [] = "Rudolf";
    cin >> request;
if (char request[] = char correct[])
    {
              cout << " correct";
    }
    else
    {
              cout << "incorrect";
     }
}

Any help is appreciated!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 744
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 32
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: comparing char with constant char

  #2  
Nov 30th, 2007
Aside from the major syntax and naming issues:

thats because your array of 20 looks like

Rudolf00000000000000
--------------------

// each 0 is actually a null character

where as the array you specify looks like this

Rudolf
------
Last edited by Killer_Typo : Nov 30th, 2007 at 10:30 pm.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,539
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: comparing char with constant char

  #3  
Nov 30th, 2007
try this: It does a case-sensitive comparison, such as "Rudolf" is not the same as "rudolf"
#include <iostream>
using namespace std;

int main()
{
    char input[20];
    char correct [] = "Rudolf";
    cin >> input;
if (strcmp(input, correct) == 0)
    {
              cout << " correct";
    }
    else
    {
              cout << "incorrect";
     }
}
Last edited by Ancient Dragon : Nov 30th, 2007 at 11:02 pm.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Aug 2007
Posts: 66
Reputation: toko is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
toko's Avatar
toko toko is offline Offline
Junior Poster in Training

Re: comparing char with constant char

  #4  
Nov 30th, 2007
thanks alot man!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC