Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,046 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,527 people online right now. Registration is fast and FREE... Join Now!




[Objective C] Help needed with this compilation error

 
Reply to this topicStart new topic

[Objective C] Help needed with this compilation error

rustix
28 Jul, 2008 - 02:29 AM
Post #1

New D.I.C Head
*

Joined: 10 Nov, 2007
Posts: 13


My Contributions
When i try to concompile

CODE

#import <stdio.h>
#import <objc/Object.h>

//----------interface--------------

@interface Fraction: Object
{
    int numerator;
    int denominator;
}

-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;

@end

//-----------implementation--------

@implementation Fraction;
-(void) print
{
    printf ("%i/%i, numerator, denominator");
}

-(void) setNumerator: (int) n
{
    numerator = n;
}

-(void) setDenominator: (int) d;
{
    denominator = d;
}
@end

//-------------program-------------

int main (int argc, char *argv[])
{
    Fraction *myFraction;

    myFraction = [Fraction alloc];
    myFraction = [myFraction init];

    [myFraction setNumerator: 1];
    [myFraction setDenominator: 3];

    printf ("The value of my fraction is: ");
    [myFraction print];
    printf ("\n");
    [myFraction free];

    return 0;
}



i get the following error

CODE

[rustix@localhost Objective-C]$ ./a.out
The value of my fraction is: 0/-1081145512, numerator, denominator


how do i sort this ?
User is offlineProfile CardPM
+Quote Post

perfectly.insane
RE: [Objective C] Help Needed With This Compilation Error
31 Jul, 2008 - 02:25 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 558



Thanked: 46 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
CODE

-(void) print
{
    printf ("%i/%i, numerator, denominator");
}


That's not an error. That's the output of your program. It is doing what you're telling it to. Looking at the above, take a look again at the printf function call there.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:09PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month