Table of Contents
show
strcat()
Append a string at the end of other
strcat(first_string,second_string);
Program: concatenating strings using string function
#include<stdio.h>
int main()
{
char s1[100];
char s2[100];
puts("Enter s1");
gets(s1);
puts("Enter s2");
gets(s2);
strcat(s1,s2);
puts("After concatenation s1 contains");
puts(s1);
return 0;
}
Output
Enter s1
sjit
Enter s2
students
After concatenation s1 contains
Sjitstudents
Program: Concatenating strings without using string function
#include<stdio.h>
int main()
{
char s1[100];
char s2[100];
int i=0,j=0;
puts("Enter s1");
gets(s1);
puts("Enter s2");
gets(s2);
while(s1[i] != '\0')
{
i++;
}
while(s2[j] !='\0')
{
s1[i] = s2[j];
i++;
j++;
}
s1[i] = '\0';
puts("After concatenation s1 contains");
puts(s1);
return 0;
}
Output
Enter s1
sjit
Enter s2
students
After concatenation s1 contains
sjitstudents
Views: 0