0% found this document useful (0 votes)
139 views2 pages

C Program To Concatenate Strings - Programming Simplified

This document provides two C code examples for concatenating strings. The first uses the strcat string library function to concatenate two strings entered by the user and displays the result. The second concatenates strings without using strcat by iterating through one string with a pointer until the null terminator is found, then copying each character of the second string after it until its null terminator is reached. The document also includes a comment asking how to concatenate strings without built-in functions, which the author provides code to demonstrate.

Uploaded by

Sachin Puri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
139 views2 pages

C Program To Concatenate Strings - Programming Simplified

This document provides two C code examples for concatenating strings. The first uses the strcat string library function to concatenate two strings entered by the user and displays the result. The second concatenates strings without using strcat by iterating through one string with a pointer until the null terminator is found, then copying each character of the second string after it until its null terminator is reached. The document also includes a comment asking how to concatenate strings without built-in functions, which the author provides code to demonstrate.

Uploaded by

Sachin Puri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

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

You might also like