Contribute
Register

C++ Programming question.

Joined
Mar 3, 2010
Messages
76
Motherboard
GA-P55M-UD2
CPU
Intl Core i5
Graphics
EVGA GTX 750TI 2GB FTW
Mac
  1. MacBook Air
Classic Mac
Mobile Phone
  1. 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,285
Motherboard
Gigabyte GA-P55M-UD4
CPU
i7-860
Graphics
9800 GT
Mac
  1. MacBook Pro
Mobile Phone
  1. 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,417
Motherboard
ASUS TUF Z390-PRO GAMING - 2606 - UEFI
CPU
i9-9900K
Graphics
Vega 64
Mac
  1. MacBook Pro
  2. Mac Pro
Classic Mac
  1. Power Mac
  2. PowerBook
Mobile Phone
  1. 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
76
Motherboard
GA-P55M-UD2
CPU
Intl Core i5
Graphics
EVGA GTX 750TI 2GB FTW
Mac
  1. MacBook Air
Classic Mac
Mobile Phone
  1. iOS
:) I will give it a shot, thanks guys!
 
Joined
Jul 6, 2010
Messages
8
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