Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:14:04+00:00 2026-05-29T04:14:04+00:00

I have an array of indices [1 … 20]. The first 4 elements of

  • 0

I have an array of indices [1 … 20]. The first 4 elements of the indicesArray are linked to a file of a certain type (call it type A), the other 16 are linked to type B.

I shuffle the array at random. I now wish to extract 4 of the indices but at most only one of the 4 can be of type A.

I think I need to use the enum function here to define indices 1-4 as “type A” & indices 5-20 as “type B”, then if I looked at e.g. the first element of my freshly randomised indicesArray[0] I could tell which type it is & act accordingly.

The way I’ve seen enum used from examples it goes something like:

enum category { typeA = 0, typeB };

Is it possible to assign indices 1-4 to typeA & the rest to typeB, or am I on the wrong track here? thanks in advance.

Edit to include code snippet

I tried to test this & ran into an error right away

 #import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

int* indices = malloc(20*sizeof(int));

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

    indices[i] = i;

}

enum category {typeA, typeB};


enum category categoryForIndex(int index) {
    if (index >= 1 && index <= 4) {
        return typeA;
    } else {
        return typeB;
    }
}

[pool drain];
return 0;

}

When i try to compile this I get the error “nested functions are disabled, use -fnested-functions to re-enable”, which usually happens when a second main gets thrown into the mix by accident, or someething like that. Any ideas?

Edit to include some code which shows how to put the solution into practice

#import <Foundation/Foundation.h>

enum category {typeA, typeB};

enum category categoryForIndex(int index) {
if (index >= 1 && index <= 4) {
    return typeA;
   } else {
    return typeB;
    }

}

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

int* indices = malloc(20*sizeof(int));

for (int i=1; i<=20; i++) {

    indices[i] = i;

}


NSLog(@"index[0] is %i:", indices[16]);

enum category index;

index = indices[16];

switch (categoryForIndex(index)) {   //this tests to see what category 16 belongs to
    case typeA:
        NSLog(@"index is of type A");   
        break;
    case typeB:
        NSLog(@"index is of type B");
        break;
    default:
        NSLog(@"index not valid");
        break;
}

 [pool drain];
 return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:14:04+00:00Added an answer on May 29, 2026 at 4:14 am

    You’re off track. You cannot assign 1-4 a given enum. Enum constants have precisely one value, and only one. What you can do is use an enum to define two types, say typeA and typeB as you’ve already done, and then define a function that maps an index back to a type, e.g.

    enum category categoryForIndex(int index) {
        if (index >= 1 && index <= 4) {
            return typeA;
        } else {
            return typeB;
        }
    }
    

    Now you have a way to categorize your indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that I have an array of random reals, how do I the indices
I have the following code which first selects elements of a NumPy array with
In PHP I can name my array indices so that I may have something
I have a bidimensional Object array in Java. Some indices aren´t used, because they
An array is defined of assumed elements like I have array like String[] strArray
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I have an array with dates as indices which I'm plotting. I'd like to
I have an array with numerical indices, which looks like this (after I unset
Say I have an array of values: values = 1:100; an array of indices:
I have a large array. I have some Java code for identifying indices for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.