Thread: Please Help

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Please Help

    Hello All

    I tried to write this code. A structure is declared in the main function. I tried to pass the structure as a function parameter into function test. But it doesn’t work.

    I was hoping if someone can just see my code take about 2-3 mins of there time and tell me where I went wrong and correct this code.

    Any help big or small will be highly appreciated.

    Code:
    #include <stdio.h>
    
    typedef struct{
    	int number;
    	int place;
    	int postcode;
    } information_t;
    
    int test(information_t *in);
    
    int main()
    {
    	information_t information;
    	information *in;
    	
    printf(" Please enter the number: ");
    scanf(" %d",&information.number);
    
    printf(" Please enter the place: ");
    scanf(" %d",&information.place);
    
    printf(" please enter the postcode: ");
    scanf(" %d",&information.postcode);
    
    test(&information_t  *in);
    
    return 0;
    }
    
    int test(information_t  *in)
    {
    	int position;
    	position= scanf(" %d%d%d", &in->number, &in->place, &in->postcode);
    	
    return(position);
    }

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    29
    Code:
    #include <stdio.h>
    
    typedef struct{
    	int number;
    	int place;
    	int postcode;
    } information_t;
    
    int test(information_t *in);
    
    int main()
    {
    	information_t information;
    	information_t *in; /* this line was wrong */
    	
    printf(" Please enter the number: ");
    scanf(" %d",&information.number);
    
    printf(" Please enter the place: ");
    scanf(" %d",&information.place);
    
    printf(" please enter the postcode: ");
    scanf(" %d",&information.postcode);
    
    test(in); /* test takes only one parameter: a pointer to a function */
    
    return 0;
    }
    
    int test(information_t  *in)
    {
    	int position;
    	position= scanf(" %d%d%d", &in->number, &in->place, &in->postcode);
    	
    return(position);
    }
    That will compile just fine.

Popular pages Recent additions subscribe to a feed