pointers and functions, with scanf, please help me

This is a discussion on pointers and functions, with scanf, please help me within the C Programming forums, part of the General Programming Boards category; Code: /* Terrance Lynch November 2, 2002 Pointers to functions test */ #include <stdio.h> #include <stdlib.h> #include <string.h> void test(int ...

  1. #1
    CIS and business major
    Join Date
    Aug 2002
    Posts
    194

    Exclamation pointers and functions, with scanf, please help me

    Code:
    /*
    	Terrance Lynch
    	November 2, 2002
    	Pointers to functions test
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void test(int *int_pointer, int *t, int *z);
    void times(int *int_pointer, int *t, int *z);
    void RequestTwoIntegers(int *int_pointer, int *t, int *z);
    
    int main()
    {
    	int i = 50, *p = &i;
    	int x;
    	int y;
    
    	int *t = &x;
    	int *z = &y;
    
    
    	printf("i before the call to test = %i\n", i);
    	
    	RequestTwoIntegers(p, t, z);
    	times(p, t, z);
    	test(p, t, z);
    	
    
    }
    
    void test(int *int_pointer, int *t, int *z)
    {
    	
    	
    	printf("i after the call to test = %i\n", *int_pointer);
    }
    
    void times(int *int_pointer, int *t, int *z)
    {
    	*int_pointer = *t * *z;
    }
    
    void RequestTwoIntegers(int *int_pointer, int *t, int *z)
    {
    
    	// request two integers from the user
    	printf("Please enter two integers: \n");
    	scanf("%i", &t);
    	scanf("%i", &z);
    
    
    }

    I'm having trouble getting t and z from the user, the bottom function RequestTwoIntegers.

    How do I set it up to accept user input, should I use scanf???

  2. #2
    Registered User The Junglist's Avatar
    Join Date
    Nov 2002
    Posts
    42
    Code:
    void RequestTwoIntegers(int *int_pointer, int *t, int *z)
    {
    
    	// request two integers from the user
    	printf("Please enter two integers: \n");
    	scanf("%i", t);     //Don't include the '&'
    	scanf("%i", z);
    
    
    }
    t is a local pointer in the function RequestTwoIntegers(), so you shouldn't pass the address of the pointer.

  3. #3
    CIS and business major
    Join Date
    Aug 2002
    Posts
    194

    Cool

    cool, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 07:53 PM
  5. pointers, functions, parameters
    By sballew in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 10:33 PM

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