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 589047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:22:57+00:00 2026-05-13T15:22:57+00:00

I wrote a simple program to understand how objective-c works. This program is the

  • 0

I wrote a simple program to understand how objective-c works. This program is the i-ching, an ancient divination based on six lines response, calculated after launching three coins for six times, and then build an hexagram which is the reponse.

I am stuck at this, that I am sure has simple solution. This is how I defined the lines, I know it’s not the best design, but I am trying to use as much technology as possible.
Supposing you launch a coin, it can be 3 or 2 depending on the side, three coins result in possible value 6,7,8,9.

 /**
  * identifying a coin
  */
 typedef enum {
  head=3,
  tail=2
 } Coin;

 /**
  identify a line, three coins with a side value of
  2 and 3 can result in 6,7,8,9
  */
 typedef enum {
  yinMutable=tail+tail+tail, // 6 --> 7
  yang=tail+tail+head,  // 7 
  yin=head+head+tail,   // 8
  yangMutable=head+head+head // 9 --> 8
 } Line;

 /**
  The structure of hexagram from bottom "start" to top "end"
  */
 typedef struct {
  Line start;
  Line officer;
  Line transit;
  Line minister;
  Line lord;
  Line end;
 } Hexagram;

The first problem I encounter with this design is to assign a value at each line in Hexagram. The first launch should fill value in start, the second in officer….and so on.
But can be easily solved with a switch case…altough I don’t like it.

1) First question: I wonder if there is some function like in javascript or c# like
foreach (property in Hexagram) that let me browse the properties in their declaration order, that would solve my problem.

2) Second question: as an alternative way I used an array of Line:

Controller.m
....
Line response[6]
....

-(id) buildHexagram:... {

for(i =0.....,i++).....
  response[i]=throwCoins;

// I omit alloc view and the rest of the code...then
[myview buildSubview:response]; 
}


----------------------
subView.m


-(id) buildSubView:(Line[]) reponse {

NSLog(@"response[0]=%o",[response objectAtIndex[0]]); <--- HERE I GOT THE ERROR
}

but then, whit this solution I got an error EXC_BAD_ACCESS
So obviously I am misunderstanding how array works in objective-c or c !
In the hope I have made myself clear enough, can someone point out the solution to the first question, and what I am doing wrong in the second option.

thanks
Leonardo

  • 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-13T15:22:58+00:00Added an answer on May 13, 2026 at 3:22 pm

    You’ve created a C array of Line – to access the elements you need to use C style array accessors.

    So instead of

    [response objectAtIndex[0]]
    

    use

    response[0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this simple C program: int main() { int i; int count =
I wrote this simple Java program which connects to internic server and returns the
I am trying to understand the fundamentals of blocks. I wrote this simple test:
I wrote a simple program to solve the math problem: A^2+B^2 = 12 A*B
I wrote a simple program to test a theory that finally block will always
I wrote a simple program in java web forms but i am receiving the
I wrote a simple test program for opencv to see if it's working after
I wrote a simple C program: #include <unistd.h> #include <stdio.h> int main( int argc,
A while back I wrote a simple python program to brute-force the single solution
I recently wrote a program that used a simple producer/consumer pattern. It initially had

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.