Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-05-2010, 06:16 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default How do I need to define this?

Hello,

I'm having trouble finding the solution for the following problem:

I have this piece of code:
Code:
int vraagNummers[result.count];
int i;
int j;
int r;

for (i = 0; i < result.count; i++) {
vraagNummers[i] = i;
}

for (i = (result.count - 1); i > 0; i--) {
r = arc4random() % (i + 1);
if (r < i) {
j = vraagNummers[i];
vraagNummers[i] = vraagNummers[r];
vraagNummers[r] = j;
}
}

for (int i = 0; i < 50; i++) {

NSDictionary *stream = (NSDictionary *)[result objectAtIndex:vraagNummers[i]];

--rest of code--
This is giving me the following warning when I build + analyze:

Code:
Pass-by-value argument in message expression is undefined
This warning is beneath "..onary *)[result objectAtIndex:vraagNummers[i]];"

Does anyone see what I'm doing wrong here? Can you tell me the solution?

Regards,

Rick
rickrets is offline   Reply With Quote
Old 08-05-2010, 06:23 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by rickrets View Post
Code:
int vraagNummers[result.count];
This is a problem. A declaration of a C-style array must specify a constant as the number of elements in the array. result.count is not a constant. One solution, if you know for a fact that result.count can never be larger than, say, 100, is to declare int vraagNummers[100];
RLScott is offline   Reply With Quote
Old 08-05-2010, 06:30 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

--EDIT--

You are right, I had to change every result.count to some int...

Is there no way to get it filled with something changeable??

Last edited by rickrets; 08-05-2010 at 06:34 AM.
rickrets is offline   Reply With Quote
Old 08-05-2010, 07:06 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Hmm,

It's all working now, I changed the for loop into:

Code:
for (int i = 0; i < result.count; i++) {
Need to figure out how to grab 50 of them (random)...
rickrets is offline   Reply With Quote
Old 08-05-2010, 07:52 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by rickrets View Post
--EDIT--

You are right, I had to change every result.count to some int...

Is there no way to get it filled with something changeable??
The number 100 in [100] does not fill the array with anything. It just allocates a certain amount of memory. It does not hurt to allocate more than you need, unless that amount is so big that you start running out of memory. One instance of an int array of [100] elements is not going to hurt. Even [1000] would be fine. If you really need to allocate an array of variable size, then you should look at the C library functions available in malloc.h. But I would avoid that as much as possible because it brings its own special problems if you are not very careful.
RLScott is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 323
10 members and 313 guests
alexP, arash5500, gordo26, HemiMG, mediaspree, nobstudio, Objective Zero, Sloshmonster, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0