Amazon.com Widgets scanf broken in xcode?
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2013, 01:54:04 AM
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
|-+  Old Stuff
| |-+  Program Examples
| | |-+  Chapter 5
| | | |-+  scanf broken in xcode?
Pages: [1]   Go Down
Print
Author Topic: scanf broken in xcode?  (Read 4829 times)
pcmxa
Newbie
*
Posts: 5


Email




« on: June 02, 2009, 01:18:28 PM »

Has anyone run into problems with scanf in xcode?  I was working through chapter 5 and doing the GCD example.  The code worked fine.  Now though when I try and run it, nothing happens after entering the numbers.  No other programs with scanf will work either.  if I comment out the scanf line and hard code integer values, the program works fine.  has anyone else run into this?

Code: (Objective-C)
#import <Foundation/Foundation.h>

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

    // insert code here...

//decalre variables

unsigned int u, v, temp;

//ask for two integers

NSLog(@"PLEASE TYPE IN TWO POSITIVE INTEGERS");
scanf("%u%u", &u, &v);

//algorithm for finding GCD using while

while (v != 0 ){
temp = u % v;
NSLog(@"%u modulus %u is %u", u, v, temp);
u = v;
v = temp;
}

NSLog(@"Their greatest common denominator  %u", u);

    [pool drain];
    return 0;
}
Logged
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #1 on: June 02, 2009, 01:24:08 PM »

Are you pressing Return or Enter at the end of your input line?   See these threads:

http://classroomm.com/objective-c/index.php?topic=544.0
http://classroomm.com/objective-c/index.php?topic=31.0

Cheers,

Steve Kochan
Logged
lafOC
Newbie
*
Posts: 1






« Reply #2 on: January 31, 2010, 05:08:12 PM »

Those two links are helpful.  I'm using a macbook pro laptop and the enter and return are on the same button, but if you shift while pushing the enter/return button scanf will work.  Unshifted must be the Return and Shifted must be the Enter.
Logged
knportal
Newbie
*
Posts: 1






« Reply #3 on: November 29, 2010, 04:02:00 AM »

Thank you so much for posting this - i thought i was going crazy.
Logged
karabantos
Newbie
*
Posts: 21






« Reply #4 on: September 25, 2012, 03:50:25 AM »

it's just not working  Huh

I've been trying but nothing happens

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.