Amazon.com Widgets C instructions and XCode 4.2
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 23, 2014, 10:52:46 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Programming in Objective-C, 4th edition
| |-+ General Discussion
| | |-+ C instructions and XCode 4.2
Pages: [1] Go Down
Print
Author Topic: C instructions and XCode 4.2 (Read 1087 times)
reocui
Newbie
*
Posts: 3






on: February 15, 2012, 05:31:44 AM

Apologies, I'm just a beginner jumping 30 years from my previous programming experience..

I have tried to run a couple of programs from the book with XCode 4.2, defined as "Empty Application" projects - it seems ok, however I do not succeed to satisfy a "scanf" call: I have copied the program at page 79 (triangular number) in to main.m than built and run it, and NSLog works correctly while scanf does not stop for an input - I have tried with the debugger (dbg) but the program goes through the assembler scanf routine (I guess, I cannot read it) without pausing anywhere for input.
I'm sure it's something absolutely simple, but if someone could help me out..

many thanks!
PS I noticed that the "return"  statement in the book version is outside the autoreleasepool block, while the precoded main version by XCode  has the return UIApplication xxxxxxxxxxxxxx inside - difference?
Logged
Waiting
Global Moderator
Full Member
*****
Posts: 113






Reply #1 on: February 15, 2012, 12:44:40 PM

We cant help unless you post your code.
Logged
reocui
Newbie
*
Posts: 3






Reply #2 on: February 16, 2012, 02:28:12 AM

sorry
other stuff in files as standard set up by Xcode for an "Empty Application", i.e. AppDelegate.h/m, info.plist, Frameworks UIKit, Foundation, CoreGraphics
thanks

#import <UIKit/UIKit.h>

#import "TNEAAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
       
        int n, number, triangularNumber;
       
        NSLog (@"What TriNumber do you want?");
        scanf ("%i", &number);
       
        triangularNumber=0;
        for (n=1;n<=number;+n) triangularNumber +=n;
       
               
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([TNEAAppDelegate class]));
    }
}
Logged
Waiting
Global Moderator
Full Member
*****
Posts: 113






Reply #3 on: February 16, 2012, 03:39:21 AM

I think you have chosen an empty iOS application.

You need to choose mac os x and command line application to follow the examples at the start of the book.

Your example seems to have linked to a UIKit file rather than the foundation file.
Logged
reocui
Newbie
*
Posts: 3






Reply #4 on: February 17, 2012, 04:35:05 PM

right, I guess I'll have to download again Xcode for mac os x

strange though, that I can use the "console" of Xcode for output (NSLog) and controlling gdb but bot to enter something for scanf

thanks
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #5 on: February 17, 2012, 05:42:38 PM

You don't need to download XCode again, just start with the correct project template in XCode.

Cheers,

Steve
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.