codescracker


c

C strcat()



« Previous Chapter Next Function »


strcat()

The strcat() function concatenates a copy of str2 to str1 and terminates str1 with a null. The null terminator originally ending str1 is overwritten by the first character of str2. The string str2 is untouched by the operation. If the arrays overlap, the behaviour of strcat() is undefined.

The strcat() function returns str1.

Remember, no bounds checking takes place, so it is the programmer's responsibility to ensure that str1 is large enough to hold both its original contents and those of str2.

strcat() Syntax

Following is the syntax of the strcat() function :

#include<string.h>
char *strcat(char *str1, const char *str2);

strcat() Example

Following program appends the first string read from stdin to the second. For example, assuming the user enters hello and there, the program prints therehello.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	clrscr();
	char s1[80], s2[80];
	gets(s1);
	gets(s2);
	strcat(s2, s1);
	printf(s2);
	getch();
}

« Previous Chapter Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test