cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Help comparing char arrays
Help comparing char arrays
Nov 20, 2012 at 5:34pm UTC
jarellh94
(10)
My program is supposed to pass 2 character array's to a function to see if they're equal. When I compare the two arrays, my program only compares the first letter. I want to compare the whole word.
char searchScore(char user[], Student curStudent[])
{
for(int i = 0; i < 8; i++)
{
if(*user == *curStudent[i].username)
return curStudent[i].grade;
}
return 0;
}
Nov 20, 2012 at 5:58pm UTC
ResidentBiscuit
(4459)
Well first off, these aren't two char arrays. You have a char array and a Student array. Does your Student struct/class have a char member?
Nov 20, 2012 at 6:01pm UTC
jarellh94
(10)
Yea sorry I should have mentioned that. curStudent[i].username is a char array. At this part of the program it is defined as a 6 letter string.
Nov 20, 2012 at 6:06pm UTC
ResidentBiscuit
(4459)
Well, if you insist on using char arrays instead of std::string, then use this:
http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
It's in string.h
Nov 20, 2012 at 6:28pm UTC
jarellh94
(10)
Thanks
Topic archived. No new replies allowed.