Someone To Debug My Prog!!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • momotaro
    Contributor
    • Sep 2006
    • 357

    Someone To Debug My Prog!!!!

    am supposed to fill an array of structure with some info and retreive it ....
    what is wrong with my code! plz help!


    Code:
    #include<stdio.h>
    
    typedef struct
    {
    	char name[20];
    	double salary;
    	int rank;
    }employee;
    
    void fill_array(employee);
    employee display(employee);
    
    void main()
    {
    	employee arr[2], e;
    	fill_array(arr[2]);
    	e = display(e);
    	while(1);
    
    }
    
    void fill_array(employee arr)
    {
    	int i;
    	for(i = 0; i<2; i++)
    	{
    		printf("name --> ");
    		scanf("%s", arr[i].name);
    		printf("salary --> ");
    		scanf("%lf", arr[i].salary);
    		printf("rank --> ");
    		scanf("%d", arr[i].rank);
    	}
    }
    
    employee display(employee e)
    {
    	employee arr[2];
    	int i;
    	for(i = 0; i<2; i++)
    	{
    		printf("\n\n\n\nname --> ", arr[i].name);
    		printf("\nsalary --> ", arr[i].salary);
    		printf("\nrank --> ", arr[i].rank);
    	}
    	return e;
    }
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    fixed a few errors, I think fill_array() is working - you now need to work on display()
    Code:
    #include<stdio.h>
    
    typedef struct
    {
    	char name[20];
    	double salary;
    	int rank;
    }employee;
    
    void fill_array(employee[]);
    employee display(employee);
    
    int main()
    {
    	employee arr[2], e;
    	fill_array(arr);   // ** removed [2]
    	e = display(e);
    	while(1);
    
    }
    
    void fill_array(employee arr[])  // ** added []
    {
    	int i;
    	for(i = 0; i<2; i++)
    	{
    		printf("name --> ");
    		scanf("%s", &arr[i].name);  // ** added &
    		printf("salary --> ");
    		scanf("%lf", &arr[i].salary);
    		printf("rank --> ");
    		scanf("%d", &arr[i].rank);
    	}
    }
    
    employee display(employee e)
    {
    	employee arr[2];
    	int i;
    	for(i = 0; i<2; i++)
    	{
    		printf("\n\n\n\nname --> ", arr[i].name);
    		printf("\nsalary --> ", arr[i].salary);
    		printf("\nrank --> ", arr[i].rank);
    	}
    	return e;
    }

    Comment

    • momotaro
      Contributor
      • Sep 2006
      • 357

      #3
      thx! this is the worked out version with still one error!:
      Error 4 --> error C2143: syntax error : missing ';' before 'type'
      Code:
      #include<stdio.h>
      
      typedef struct
      {
      	char name[20];
      	double salary;
      	int rank;
      }employee;
      
      void fill_up(employee arr[]);
      void display(employee arr[]);
      
      void main()
      {
      	employee arr[2];
      	fill_up(arr);
      	display(arr);
      	while(1);
      }
      
      void fill_up(employee arr[])
      {
      	int i;
      	for(i = i; i < 2; i++)
      	{
      		printf("name --> ");
      		scanf(" %s", &arr[i].name);
      		printf("salary --> ");
      		scanf("%lf", &arr[i].salary);
      		printf("rank --> ");
      		scanf("%d", &arr[i].rank);
      	}
      
      void display(employee arr[])  <-- error missing ';'
      {
      	int i;
      	for(i = i; i < 2; i++)
      	{
      		printf("\n\n\n\nname --> ", &arr[i].name);
      		printf("\nsalary --> ", &arr[i].salary);
      		printf("\nrank --> ", &arr[i].rank);
      	}
      }

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Originally posted by momotaro
        thx! this is the worked out version with still one error!:
        Error 4 --> error C2143: syntax error : missing ';' before 'type'
        Code:
        #include<stdio.h>
        
        typedef struct
        {
        	char name[20];
        	double salary;
        	int rank;
        }employee;
        
        void fill_up(employee arr[]);
        void display(employee arr[]);
        
        void main()
        {
        	employee arr[2];
        	fill_up(arr);
        	display(arr);
        	while(1);
        }
        
        void fill_up(employee arr[])
        {
        	int i;
        	for(i = i; i < 2; i++)
        	{
        		printf("name --> ");
        		scanf(" %s", &arr[i].name);
        		printf("salary --> ");
        		scanf("%lf", &arr[i].salary);
        		printf("rank --> ");
        		scanf("%d", &arr[i].rank);
        	}
        }
        
        void display(employee arr[])  <-- error missing ';'
        {
        	int i;
        	for(i = i; i < 2; i++)
        	{
        		printf("\n\n\n\nname --> ", &arr[i].name);
        		printf("\nsalary --> ", &arr[i].salary);
        		printf("\nrank --> ", &arr[i].rank);
        	}
        }
        You were missing a single '}' to end your fill_up function...I've added it.

        Comment

        • momotaro
          Contributor
          • Sep 2006
          • 357

          #5
          THX !!! but am supposed to have the info that i ve put in the array to be be printed back but it does not happened!

          Comment

          Working...