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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:42:04+00:00 2026-06-07T04:42:04+00:00

I have been developing a very simple text game using Objective C and Xcode.

  • 0

I have been developing a very simple text game using Objective C and Xcode. It is almost done but I am having a problem, the scanf method stops the loop and asks for user input while I need the computer to be running the rest of the loop, the solution I came up with was running two while loops at the same time, one being the logic loop and another being a loop for user input.

I have been doing my research and it looks like using threads are the way to go, I just have not found a tutorial that will break it down for a n00b in Objective C (I am decent in java, I just have never worked with threads). If anybody could explain them or link me to a very broken down tutorial that would be great. Or if anybody has another idea I am open to anything else.

Necessary Code (The scanf I am having a problem with has asterisks on the line):

 while(running != 0)
    {
        if(gameState == 1)
        {
            if(timeToGenerateNum == true)
            {
                while(randNumber < 10000000)
                {
                    randNumber = arc4random() % 100000000;
                }
                NSLog(@"%i", randNumber);
                timeToGenerateNum = false;
            }
            else 
            {
                while(time <= 2500)
                {
                    NSLog(@"Testing");
                    time++;
  ******************scanf("%i", &userNum);************************
                    if(userNum == randNumber)
                    {
                        score += time;
                        time = 0;
                        timeToGenerateNum = true;
                    }
                }
                NSLog(@"Game Over! Your score was %i!", score);
                running = 0;
            }
        }
        else if(gameState == 2)
        {
            NSLog(@"To play, simply type in the number that appears on the screen.");
            NSLog(@"But be careful, you only have a short amount of time before GAME OVER!");
            NSLog(@"The quicker you type in the number the more score you get!");
            NSLog(@"Are you ready to start, if so type '1' and press enter!");
            scanf("%i", &gameState);
        }
    }
  • 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-06-07T04:42:06+00:00Added an answer on June 7, 2026 at 4:42 am

    You’re going to have to learn a bit about BSD (Unix, Linux) input/output to pull this off: replace your call to scanf with a non-blocking function you write to acquire input from the user’s keyboard.

    This function should immediately return whatever the user typed, or immediately return with a zero character count if she didn’t type anything.

    Read up on the select(2) system call, and keep in mind that keyboard input (standard input) is the first file descriptor, file descriptor zero.

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

Sidebar

Related Questions

I have lately been developing a very simple app for iOS with PhoneGap. All
I have been developing with objective C and the Cocoa framework for quite some
I have been developing applications using VB.net for the past 5 years. As I
In the past, I have been developing in a very amateurish fashion, meaning I
I will be very direct with my question. I have been developing web applications
I'm developing an advanced rich text editor in c# but have stumbled upon a
I have been asked to write a (very) simple program for a set of
I'm developing a new client-server app (.Net) and have up until now been using
We have been developing code using loose coupling and dependency injection. A lot of
I've been developing a very large LOB app using my flavor of M-V-VM which

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.