Tuesday, July 19, 2011

Program to concanate two strings using pointer and function by passing strings as parameter

/*Serial No.120     [swami97.cpp]*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void concat(char *t, char *p);
void main()
{
char str1[10],str2[10];
int l;
clrscr();
printf("Enter the string==>");
gets(str1);
printf("Enter the string==>");
gets(str2);
concat(str1,str2);
getch();
}
void concat(char *s1, char *s2)
    {
    char new_str[20];
    int i=0;
    while(*s1)
        {
        new_str[i]=*s1;
        *s1++;
        i++;
        }
    while(*s2)
        {
        new_str[i]=*s2;
        s2++;
        i++;
        }
    new_str[i]='\0';
    puts(new_str);
    }

No comments:

Post a Comment

If you have any doubt, feel free to ask...