Challenge 16 Won't even build- Any Help?


#1

Folks,

Code below just replies Build Failed but does not indicate any errors. Seems similar to some other postings here so I am perplexed. Any help is most appreciated. Finding this more frustrating than I expected.

#import <Foundation/Foundation.h>
#include <readline/readline.h>

int main(int argc, const char * argv[])
{

@autoreleasepool
{
    
    
    // Get input for where to start countdown
    NSLog(@"Where should I start counting? ");
    const char *startCountdownChar = readline(NULL);
    NSString *startNumberNum = [NSString stringWithUTF8String:startCountdownChar];
    
    // Convert input from ASCII to number type integer
    NSInteger i = [startNumberNum integerValue];
    
    
    for (i = i; i > -1; i = i - 3)
    {
        
        NSLog(@" %li ", i );
        
        if (i % 5 == 0)
        {
            NSLog(@" Found one!");
        }
    }

    
}
return 0;

}


#2

I copied and pasted your code into my program, with the only difference of using #import <readline/readline.h> instead of #include <readline/readline.h>, and it compiled and ran successfully.
There was a section of the book that said using #import was more efficient than #include as the header file only has to be imported once, instead of literally dumping a copy/paste from the header file for each object that uses it. From that point on, I just started using #import for everything.

Output:

2014-07-29 15:07:28.014 C16-Challenge2 - Using readline()[19935:303] Where should I start counting? 
3535

2014-07-29 15:07:30.869 C16-Challenge2 - Using readline()[19935:303]  35 
2014-07-29 15:07:30.870 C16-Challenge2 - Using readline()[19935:303]  Found one!
2014-07-29 15:07:30.870 C16-Challenge2 - Using readline()[19935:303]  32 
2014-07-29 15:07:30.871 C16-Challenge2 - Using readline()[19935:303]  29 
2014-07-29 15:07:30.871 C16-Challenge2 - Using readline()[19935:303]  26 
2014-07-29 15:07:30.871 C16-Challenge2 - Using readline()[19935:303]  23 
2014-07-29 15:07:30.871 C16-Challenge2 - Using readline()[19935:303]  20 
2014-07-29 15:07:30.872 C16-Challenge2 - Using readline()[19935:303]  Found one!
2014-07-29 15:07:30.872 C16-Challenge2 - Using readline()[19935:303]  17 
2014-07-29 15:07:30.872 C16-Challenge2 - Using readline()[19935:303]  14 
2014-07-29 15:07:30.873 C16-Challenge2 - Using readline()[19935:303]  11 
2014-07-29 15:07:30.873 C16-Challenge2 - Using readline()[19935:303]  8 
2014-07-29 15:07:30.873 C16-Challenge2 - Using readline()[19935:303]  5 
2014-07-29 15:07:30.873 C16-Challenge2 - Using readline()[19935:303]  Found one!
2014-07-29 15:07:30.877 C16-Challenge2 - Using readline()[19935:303]  2 
Program ended with exit code: 0

#3

[quote]“What is the difference between #import and #include? #import is faster and more efficient. When the compiler sees the #include directive, it makes a dumb copy-and-paste of the contents of the file to include. When the compiler sees the #import directive, it first checks to see if another file may have already imported or included the file.”

Excerpt From: Mikey Ward. “Objective-C Programming.” iBooks. itun.es/gb/JbUvT.l[/quote]


#4

Thank you very much. Remember reading that now. Did Not know it would make such a significant difference. Really appreciate the help.


#5

Made that change and still will not compile. Was really hoping that it was something easy like that (and maybe it is).

Just get Build Failed from Xcode with no other message.

#import <Foundation/Foundation.h>
#import <readline/readline.h>

int main(int argc, const char * argv[])
{
    
    @autoreleasepool
    {
        
        
        // Get input for where to start countdown
        NSLog(@"Where should I start counting? ");
        const char *startCountdownChar = readline(NULL);
        NSString *startNumberNum = [NSString stringWithUTF8String:startCountdownChar];
        
        // Convert input from ASCII to number type integer
        NSInteger i = [startNumberNum integerValue];
        
        
        for (i = i; i > -1; i = i - 3)
        {
            
            NSLog(@" %li ", i );
            
            if (i % 5 == 0)
            {
                NSLog(@" Found one!");
            }
        }
        
        
    }
    return 0;
}

#6

This link should get you going.

http://forums.bignerdranch.com/viewtopic.php?f=452&t=8819&p=25020&hilit=readline#p25020

Mitch