Sunday, 9 March 2014

Writing strings using %s format.

Writing strings using %s format.

Code for Writing strings using %s format in C Programming

 main()                                                      
   {                                                           
       char  country[15] = "United Kingdom";            

       printf("\n\n");                                         
       printf("*123456789012345*\n");                          
       printf(" --------------- \n");                          
                                                               
       printf("%15s\n", country);                            
       printf("%5s\n", country);                             
       printf("%15.6s\n", country);                          
       printf("%-15.6s\n", country);                         
       printf("%15.0s\n", country);                          
       printf("%.3s\n", country);                            
       printf("%s\n", country);                              
       printf("---------------- \n");                          
   }                                                           


Output                                                      
                                                               
   *123456789012345*                                           
    ------------------
     United Kingdom                                           
    United Kingdom                                           
             United                                           
    United                                                    
                                                             
    Uni
    United Kingdom

No comments:

Post a Comment