Pointers and Functions

Using pointers and functions to reduce fraction

Page 1 of 1

2 Replies - 888 Views - Last Post: 03 March 2010 - 09:28 AM Rate Topic: -----

#1 girly_engineer  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 02-February 09

Pointers and Functions

Posted 03 March 2010 - 09:07 AM

deleted

This post has been edited by girly_engineer: 03 March 2010 - 01:07 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Pointers and Functions

#2 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 545
  • View blog
  • Posts: 1,420
  • Joined: 22-August 09

Re: Pointers and Functions

Posted 03 March 2010 - 09:16 AM

Your problem is in the get_int routine. I have corrected it for you below. The routine is called from the get_fraction routine with it's two parameters which are pointers to type int. The scanf routine therefore does not require the address-of & operator, as that would make them pointer to pointer to int. Also the while statement needs a dereference on both the original_num and original_denom as you are accessing the int rather than referring to it's pointer.

You also didn't put any types for the parameters of get int.

void get_int(int *original_num, int *original_denom) 
{ 
    do 
    { 
        printf("Numerator: "); 
        scanf("%d", original_num); 
        while(getchar() != '\n'); 
        if(*original_num <= 0) 
        { 
             printf("Please enter an integer greater than 0\n"); 
        }  
    } while(*original_num <= 0); 
 
    do 
    { 
        printf("Denominator: "); 
        scanf("%d", original_denom); 
        while(getchar() != '\n'); 
        if(*original_denom <= 0) 
        { 
            printf("Please enter an integer greater than 0\n"); 
        }  
    } while(*original_denom <= 0); 
 
} 



Hope you followed all of that.
Was This Post Helpful? 1
  • +
  • -

#3 girly_engineer  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 02-February 09

Re: Pointers and Functions

Posted 03 March 2010 - 09:28 AM

Thank you very much. I think I need to read over pointers and functions again until I completely understand. I was under the impression that I couldn't use the functions void get_int and void get_fraction with the same parameters :sad3:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1