Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Concatenation of strings

Posted By: Alice Hughes     Category: C Programming     Views: 1830

Concatenation of strings.

Code for Concatenation of strings in C Programming

   main()                                                      
   {                                                           
       int  i, j, k ;                                          
       char   first_name[10] = {"VISWANATH"}  ;         
       char  second_name[10] = {"PRATAP"} ;             
       char    last_name[10] = {"SINGH"} ;              
       char   name[30] ;                                       
     /* Copy first_name into name */
for( i = 0 ; first_name[i] != '\0' ; i++ ) name[i] = first_name[i] ; /* End first_name with a space */
name[i] = ' ' ; /* Copy second_name into name */
for( j = 0 ; second_name[j] != '\0' ; j++ ) name[i+j+1] = second_name[j] ; /* End second_name with a space */
name[i+j+1] = ' ' ; /* Copy last_name into name */
for( k = 0 ; last_name[k] != '\0'; k++ ) name[i+j+k+2] = last_name[k] ; /* End name with a null character */
name[i+j+k+2] = '\0' ; printf("\n\n") ; printf("%s\n", name) ; } Output VISWANATH PRATAP SINGH
  
Share: 


Didn't find what you were looking for? Find more on Concatenation of strings Or get search suggestion and latest updates.

Alice Hughes
Alice Hughes author of Concatenation of strings is from London, United Kingdom.
 
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!