C program to concatenate two strings
Write a c program to concatenate two strings. Accept or statically declare two strings. Use for loo to concatenate the characters of string2 to string1. Print the concatenated string.
C progr to concatenate two strings
/* Aim: write a c program to concatenate two strings */
#include<stdio.h>
int main()
{
char string1[100] = "C programming", string2[] = " is high level language";
int i, j;
for (i = 0; string1[i] != '\0'; ++i)
{
printf("i = %d\n", i);
}
// concatenating characters
for (j = 0; s2[j] != '\0'; ++j, ++i)
{
s1[i] = s2[j];
}
string1[i] = '\0';
printf("After concatenation: ");
puts(string1);
return 0;
}
Output:
After concatenation: C programming is high level language
Comments