c program to concatenate strings | Programming Simplified
http://www.programmingsimplified.com/c-program-concatenate-strings
Home C programming C programming examples c program to concatenate strings
c program to concatenate strings
This program concatenates strings, for example if the first string is "c " and second string is "program" then on concatenating these two strings we get the string "c program". To concatenate two strings we use strcat function of string.h, to concatenate without using library function see another code below which uses pointers.
C code
#include<stdio.h> #include<conio.h> #include<string.h> main() { char a[100], b[100]; printf("Enter the first string\n"); gets(a); printf("Enter the second string\n"); gets(b); strcat(a,b); printf("String obtained on concatenation is %s\n",a); getch(); return 0; }
string concatenation. Output:
String concatenation without strcat
#include<stdio.h> void concatenate_string(char*, char*); main() { char original[100], add[100]; printf("Enter source string\n"); gets(original); printf("Enter string to concatenate\n"); gets(add); concatenate_string(original, add);
1 of 2
12/24/2012 5:40 PM
c program to concatenate strings | Programming Simplified
http://www.programmingsimplified.com/c-program-concatenate-strings
printf("String after concatenation is \"%s\"\n", original); return 0; } void concatenate_string(char *original, char *add) { while(*original) original++; while(*add) { *original = *add; add++; original++; } *original = '\0'; }
C programming: C programming examples
Guest (not verified)
Fri, 19/08/2011 - 01:06 permalink
programming help
can you please tell me how to code a program in c for string concatenation without using inbuilt function.
reply
adminPs
Fri, 19/08/2011 - 08:29 permalink
string concatenation without library function strcat
Required source code is added to content above.
reply
2 of 2
12/24/2012 5:40 PM