1

I have some data into a string and I wish to store that data in an integer array... Below is the code.

int valMines[256];

// 'b' is NSString with 256 values in it.
for(int i=0; i<[b length]; i++){
valMines[i] =  [NSString stringWithFormat:@"%d", [b characterAtIndex:i]];

NSLog(@"valMines1 is %@", valMines[i]);
}

I am getting a warning and due to that my application is not getting loaded: Assignment makes integer from pointer without a cast.

Please help

1 Answer 1

1

Your valMins is an integer array and you are assigning NSString to it. Probably you are looking something like this:

unichar valMines[256];  // make it unichar instead of int

// 'b' is NSString with 256 values in it.
for(int i=0; i<[b length]; i++){
    valMines[i] =  [b characterAtIndex:i]; // get and store the unichar

    NSLog(@"valMines1 is %d", valMines[i]);  // format specifier is %d, not %@
}
Sign up to request clarification or add additional context in comments.

8 Comments

couldn't there be anyother way of storing it in int array... Issue is I have a whole big program coded and now its problem for me to change it... Making it an unichar array instead of int is giving me lots of warnings and error.
unichar is just a typedef for unsigned short integer. If that array is needed to be integer array for other places, you can leave that with int. There will be no problem with the above code. Just make it int valMins[256] instead of unichar valMins[256].
Hmm I tried it... but its giving me some junked values while priniting... sure it should be %d??
What is the content of your string? What junked value you are getting?
Content in my string is {-1-2-3-40134523} any integer +ve and -ve values in the range of -4 to +4... But when I print on console for valMine[0] its printing 45, valMine[1] 38, for valMine[2] 48 and so on...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.