Search

Strings Concatenation in C || C Programs

Example - Sam+Vinocha = Sam Vinocha


Code -

#include <stdio.h> 
int main()  
{  
 char first_string[20]; // declaration of char array variable 
 char second_string[20]; // declaration of char array variable 
 int i;  // integer variable declaration 
    printf("Enter the first string");  
    scanf("%s",first_string);  
    printf("\nEnter the second string");  
    scanf("%s",second_string);  
 for(i=0;first_string[i]!='\0';i++);   

 for(int j=0;second_string[j]!='\0';j++)  
    {  
        first_string[i]=second_string[j];  
        i++;  
    }  
    first_string[i]='\0';  
   printf("After concatenation, the string would look like: %s", first_string);  
return 0;  

Output -


Enter the first string

Sam

Enter the second string

Vinocha

Finally your string looks like Sam Vinocha


1 view0 comments

Related Posts

See All

Program of Random Number in C || C Programs

Code - #include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { // use rand() function to generate the number printf (" The random number is: %d", rand()); pri

Getchar() function in C || C Programs

Code - #include <stdio.h> #include <conio.h> void main() { char c; printf ("\n Enter a character \n"); c = getchar(); // get a single character printf(" You have passed ")

  • 1024px-Telegram_logo.svg
  • download
  • YouTube