Array Program #3

6. Read two character arrays from user and concat (concatenate)them one after other in third array and print final
array.

#include<stdio.h>
#include<string.h>

void main()
{
     int i,j;
     char a[100],b[100],c[100];
     printf("Enter the first string\n");
     scanf("%s",a);
     printf("Enter the second string\n");
     scanf("%s",b);
     printf("First string  = %s\n", a);
     printf("Second string = %s\n", b);
     i=0;
     while(a[i]!='\0')
     {
          c[i]=a[i];
          i++;
     }
     c[i]=' ';
     i++;
      j=0;
     while(b[j]!='\0')
     {
          c[i]=b[j];
          i++;
          j++;
     }
      c[i]='\0';
     printf("Concatenated string= %s \n",c);
}

OR

#include<stdio.h>
#include<string.h>
void main()
{
     char a[10],b[100];
     printf("Enter the first string\n");
     gets(a);
     printf("Enter the second string\n");
     gets(b);
     printf("First string  = %s\n", a);
     printf("Second string = %s\n", b);
     strcat(a,b);
     printf("Concatenated string= %s \n",c);
}

OR

#include<stdio.h>
#include<string.h>
void main()
{
     char a[100],b[100],c[100];
     printf("Enter the first string\n");
     scanf("%s",a);
     printf("Enter the second string\n");
     scanf("%s",b);
     printf("First string  = %s\n", a);
     printf("Second string = %s\n", b);
     strcat(a,b);
     printf("Concatenated string= %s \n",c);
}

Output

  • Enter the first string
    hello
    Enter the second string
    world
    First string  = hello
    Second string = world
    Concatenated string= hello world


    For download this program please check the link ➡➡ Download









    Comments

    Popular

    Basic Program #3

    Pointer Program #1

    Array Program #4

    Singly Linked List program #1

    Basic program #2