Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Copying one string into another

Posted By: Brooke Hughes     Category: C Programming     Views: 5671

Copying one string into another.

Code for Copying one string into another in C Programming

main( )                                                     
   {                                                           
       char  string1[80], string2[80];                         
       int   i;                                                
                                                               
       printf("Enter a string \n");                            
       printf("?");                                            
                                                               
       scanf("%s", string2);                                   
                                                               
       for( i=0 ; string2[i] != '\0'; i++)                     
          string1[i] = string2[i];                             
                                                               
       string1[i] = '\0';                                      
                                                               
       printf("\n");                                           
       printf("%s\n", string1);                                
       printf("Number of characters = %d\n", i );              
   }
                                                           
Output                                                      
                                                               
   Enter a string                                              
   ?Manchester                                                 
   Manchester                                                  
   Number of characters = 10                                   
   Enter a string                                              
   ?Westminster                                                
   Westminster                                                 
   Number of characters = 11                                   
  
Share: 


Didn't find what you were looking for? Find more on Copying one string into another Or get search suggestion and latest updates.

Brooke Hughes
Brooke Hughes author of Copying one string into another is from London, United Kingdom.
 
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!