Sunday, March 9, 2014

C program to concatenate strings without strcat(function)

Share Post:
#include <stdio.h>
#include<conio.h>

void concatenate_string(char*, char*);

int main()
{
    char original[100], add[100];

    printf("Enter source string\n");
    gets(original);


    printf("Enter string to concatenate\n");
    gets(add);

    concatenate_string(original, add);

    printf("String after concatenation is \"%s\"\n", original);

    return 0;
}

void concatenate_string(char *original, char *add)
{
   while(*original)
      original++;

   while(*add)
   {
      *original = *add;
      add++;
      original++;
   }
   *original = '\0';
}

Note:
You need a compiler to compile and execute this program.

0 comments:

Post a Comment