General Programs

Program to concatinate two strings in C

void main()
{
char a[]={"Hello"}; //declare first char array
char b[]={"Everyone"}; //declare second char array
char c[50];
int n,i,j,k=0;
clrscr();
n=sizeof(a)+sizeof(b)-2; //store the total size of both array
for(i=0;i<sizeof(a);i++) //storing first array in the resultant array
c[i]=a[i];
for(i=sizeof(a)-1;i<n;i++,k++) //storing the second array in the resultant array
c[i]=b[k];
for(i=0;i<n;i++)
printf("%c",c[i]); //displat the result
getch();
}

No comments:

Post a Comment