Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

POINTERS TO STRUCTURE VARIABLES

Posted By: Boyce Fischer     Category: C Programming     Views: 4501

Write a program to illustrate the use of structure pointers.

Code for POINTERS TO STRUCTURE VARIABLES in C Programming

struct invent                                                    
   {                                                                
       char  *name[20];                                             
       int   number;                                                
       float price;                                                 
   };                                                               
   main()                                                           
   {                                                                
      struct invent product[3], *ptr;                              
      printf("INPUT\n\n");                                         
      for(ptr = product; ptr < product+3; ptr++)                   
        scanf("%s %d %f", ptr->name, &ptr->number, &ptr->price);  
      printf("\nOUTPUT\n\n");                                      
       ptr = product;                                               
       while(ptr < product + 3)                                     
       {
           printf("%-20s %5d %10.2f\n",                             
                    ptr->name,                                      
                    ptr->number,                                    
                    ptr->price);                                    
           ptr++;                                                   
       }                                                            
   }                                                                
                                                                    
Output                                                           
                                                                    
   INPUT   
   Washing_machine   5    7500                                           
   Electric_iron    12     350                                             
   Two_in_one        7    1250                                                
                                                                    
   OUTPUT                                                           
   Washing machine     5   7500.00                            
   Electric_iron       12   350.00                            
   Two_in_one           7   1250.00                            
  
Share: 


Didn't find what you were looking for? Find more on POINTERS TO STRUCTURE VARIABLES Or get search suggestion and latest updates.

Boyce Fischer
Boyce Fischer author of POINTERS TO STRUCTURE VARIABLES is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!