•
•
•
•
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
![]() |
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.
Any help is appreciated!!
#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!!
Aside from the major syntax and naming issues:
thats because your array of 20 looks like
where as the array you specify looks like this
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!
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!
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,539
Reputation:
Rep Power: 40
Solved Threads: 972
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Help!!! Help!!! Help!!! (Java)
Other Threads in the C++ Forum
- Previous Thread: Negative Random Numbers
- Next Thread: confused and frustrated



Linear Mode