Need help with beginner pointer functions.

This is a discussion on Need help with beginner pointer functions. within the C++ Programming forums, part of the General Programming Boards category; Hello I am new here hopefully I won't have broken any rules by the end of this post but I ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    18

    Need help with beginner pointer functions.

    Hello I am new here hopefully I won't have broken any rules by the end of this post but I need help with my project. The goal is to include these 3 pointer functions into my code(replacing whatever needs to be replaced) the functions are void halve(int* number) void readAge (int* age), and void writeAge(int age). I don't expect anyone to do it for me but if anyone could give an simple similar example that would be amazing. Here is my code(hopefully I get the tag to work). If my indentation is off it's the copy paste but it looks good in the compiler.

    Code:
    int readAge(void);
    
    void writeAge(int age);
    
    int main(void) {
    
       int age;
    
       age = readAge();
       writeAge(age);
    
       printf("Double that time and... \n", age);
       writeAge( 2 * age);
       printf("Wow that's old! \n", age);
    
       printf("Now if I cut your age in half... \n", age);
       writeAge(age / 2);
       printf("Haha you're almost a kid again! \n", age);
    
    return EXIT_SUCCESS;
    
    }
    
    int readAge(void )
    {
       int age;
       printf("How old are you?");
       scanf("%d", &age);
       return age;
    }
    
    void writeAge(int age)
    {
        printf("You are %d!\n\n", age);
    }

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    Code:
    void func_pointer( int * para)
    {
         scanf("%d", para); // it's 'para' and not "&para", since para yields an address already; 
    }
    
    int main()
    {
        int bleh; 
        func_pointer(&bleh); // pass the the address of 'bleh' instead of the value of bleh
    }
    Edit: wait, this is C-code. you should've posted this in the C board, instead of the C++ board.
    Last edited by nimitzhunter; 02-16-2011 at 08:23 PM.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    18
    I feel slightly mentally handicapped..... Thats why I could never find any help for this because I thought it was c++...... Btw your answer did compile but the program acts funny. Is there any way to move topic or do I just need to delete and make a new one?

    Edit: Actually I just made a new one but I don't know how to delete this one.
    Last edited by Mo777; 02-16-2011 at 08:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of functions
    By frktons in forum C Programming
    Replies: 29
    Last Post: 06-30-2010, 09:51 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Need some help with a beginner functions program!
    By nelledawg in forum C Programming
    Replies: 5
    Last Post: 03-03-2008, 06:05 AM
  4. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM
  5. functions and pointer arguments
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2002, 04:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21