Monday, 23 January 2012

Write a c program to concatenate two strings

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

void concatenate_string(char*, char*);

void main()
{
    char original[100], add[100];
    clrscr();
    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);
    getch();
}

void concatenate_string(char *original, char *add)
{
    while(*original!='\0')
    original++;
    while(*add)
    {
        *original = *add;
        add++;
        original++;
    }
    *original = '\0';
}

No comments:

Post a Comment