Sunday, April 01, 2012

Concatenate Two Strings without using strcat()

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str1[30], str2[20];
int i, length=0, temp;
printf("Enter the First String: \n");
gets(str1);
printf("\nEnter the Second String: \n");
gets(str2);
for(i=0; str1[i]!='\0'; i++)
length++;
temp = length;
for(i=0; str2[i]!='\0'; i++)
{
str1[temp] = str2[i];
temp++;
}
str1[temp] = '\0';
printf("\nThe concatenated string is:\n");
puts(str1);
getch();
}

No comments:

Post a Comment