Chapter Contents

Previous

Next
strcat

strcat



Concatenate Two Null-Terminated Strings

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <string.h>

char *strcat(char *to, const char *from);


DESCRIPTION

strcat adds characters from the second argument string from to the end of the first argument string to until a terminating-null character is found. The null also is copied.


RETURN VALUE

The return value is a pointer to the to string.


CAUTION

No check is made (or can be made) to see if there is room in the to string for all the characters of the combined string. Characters are copied until a null character is found in the source string, or until a protection or addressing exception occurs. A program check also can occur if the to string is not properly terminated. The effect of strcat is not defined if the to and from fields overlap.


EXAMPLE

#include <lcstring.h>
#include <stdio.h>

#define MAXLINE 100

main()
{
   char line[MAXLINE+1];
   char message[MAXLINE+11];

   puts("Enter a line of text to be translated to lowercase letters:");
   gets(line);
   strcat(strcpy(message, "INPUT: "), line);
   puts(message); /* Label and echo the input.              */
   strlwr(line);  /* Turn the input into lowercase letters. */
   strcat(strcpy(message, "OUTPUT: "), line);
   puts(message); /* Label and print the results.           */
}


RELATED FUNCTIONS

strcpy , strncat


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.