Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Reading of strings using %wc and %ws

Posted By: Raymundo Fischer     Category: C Programming     Views: 3233

Program illustrates the use of various field specifications for reading strings. When we use %wc for reading a string, the system will wait until the wth character is keyed in.

Code for Reading of strings using %wc and %ws in C Programming

   main()                                                      
   {                                                           
       int no;                                                 
       char name1[15], name2[15], name3[15];                   
       printf("Enter serial number and name one\n");           
       scanf("%d %15c", &no, name1);                           
       printf("%d %15s\n\n", no, name1);                       
       printf("Enter serial number and name two\n");           
       scanf("%d %s", &no, name2);                             
       printf("%d %15s\n\n", no, name2);                       
       printf("Enter serial number and name three\n");         
       scanf("%d %15s", &no, name3);                           
       printf("%d %15s\n\n", no, name3);                       
   }
                                                           
Output                                                      
   Enter serial number and name one                            
   1 123456789012345                                           
   1 123456789012345r                                          
   Enter serial number and name two                            
   2 New York                                                  
   2             New                                           
   Enter serial number and name three                          
   2            York                                           
   Enter serial number and name one                            
   1 123456789012                                              
   1 123456789012   r                                          
   Enter serial number and name two                            
   2 New-York                                                  
   2 New-York                                           
   Enter serial number and name three                          
   3 London                                                    
   3 London  
                                         
  
Share: 


Didn't find what you were looking for? Find more on Reading of strings using %wc and %ws Or get search suggestion and latest updates.

Raymundo Fischer
Raymundo Fischer author of Reading of strings using %wc and %ws is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
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!