Contribute
Register

C++ Programming question.

Joined
Mar 3, 2010
Messages
81
Motherboard
GA-P55M-UD2
CPU
Intl Core i5
Graphics
EVGA GTX 750TI 2GB FTW
Mac
MacBook Air
Classic Mac
Mobile Phone
iOS
Ok, this is driving me nuts, i don't see what i'm doing wrong..

I uploaded code to a pastebin for easy access and that way u guys can see the syntax highlighting. :)

http://pastebin.com/9yQisKvA

:banghead:
 
Joined
Mar 11, 2010
Messages
2,323
Motherboard
Gigabyte GA-P55M-UD4
CPU
i7-860
Graphics
9800 GT
Mac
MacBook Pro
Mobile Phone
iOS
What's the type of holdUsername ?
Are you sure you want its sizeof and not its strlen ?
 

MacMan

Administrator
Staff member
Joined
Feb 2, 2010
Messages
8,268
Motherboard
ASUS ROG STRIX Z370-E GAMING - 1601 - UEFI
CPU
i7-8700K
Graphics
Vega 64
Mac
MacBook Pro, Mac Pro
Classic Mac
Power Mac, PowerBook
Mobile Phone
iOS
I had my son a Software Engineering major look at the code and the issue is in the if statement on line 29.

He asks what are you trying to check? Is it if the entered name is less than 2 characters?

If so, then he suggested that you use "holdUsername.size()" or "holdUsername.length()".
 
Joined
Mar 3, 2010
Messages
81
Motherboard
GA-P55M-UD2
CPU
Intl Core i5
Graphics
EVGA GTX 750TI 2GB FTW
Mac
MacBook Air
Classic Mac
Mobile Phone
iOS
:) I will give it a shot, thanks guys!
 
Joined
Jul 6, 2010
Messages
9
Mac
Classic Mac
Mobile Phone
intrus22 said:
:) I will give it a shot, thanks guys!
It is definitely the 'sizeof()' function; you want it to be 'strlen()', because you are determining the length of the string (seen as a zero-terminated [NUL] sequence of printable bytes) held in the variable and *not* the size of the variable. sizeof() would probably in this case (since I don't know what type holdUsername is) return the size of a pointer, or 4 in 32-bit systems.

If the variable is a string class instance, you might be able to check it's length through a length checking method inside the class. I hate C++; praise plain ol' C forever!

-egonline
 
Top