i have some code that requires the use of a for loop to read variables from an array.
int size=sizeof names;
NSLog(@"thelast one is %d",size);
NSString *usersName=userName.text;
NSString *usersPass=passWord.text;
for (i=0; i<=size;i++){
NSString *namesArray=[names objectAtIndex:i];
NSString *passArray=[pass objectAtIndex:i];
NSLog(@"namesArray %@",namesArray);
NSLog(@"passArray %@",passArray);
if([namesArray isEqualToString:usersName]){
userValid=1;
NSLog(@"The content of arry4 is %@",namesArray);
}
if([passArray isEqualToString:usersPass]){
passValid=1;
NSLog(@"The content of arry4 is %@",passArray);
}
else {
userValid=0;
passValid=0;
}
}
I've been having some problems because every time this function is called from within the program, it's almost as if the 'sizeof names' is wrong, therefore not all values in the array are checked. I'm generally a Java programmer so i'm used to names.length, and i was told sizeof names is essentially the same thing... any help?
Cheers.
To find the length of an array, use the Array. Length() method.
The theoretical maximum Java array size is 2,147,483,647 elements. To find the size of a Java array, query an array's length property. The Java array size is set permanently when the array is initialized. The size or length count of an array in Java includes both null and non-null characters.
Don't use sizeof. Use [names count]
.
You want to use [names count] not sizeof names. Sizeof is going to give you the size of the actual names object pointer itself and not the number of elements, since it's dynamic memory type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With