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.
Don’t use sizeof. Use
[names count].