W języku C funkcja strcat () kontruje (łączy) dwa łańcuchy.
Definicja funkcji strcat()
to:
char * strcat (char * cel, const char * źródło)
Jest zdefiniowany w string.h
pliku nagłówkowym.
argumenty strcat ()
Jak widać, strcat()
funkcja przyjmuje dwa argumenty:
cel - ciąg docelowy
źródło - ciąg źródłowy
strcat()
Funkcja Łączy destination
łańcuch i source
łańcuch, a wynik jest przechowywany w destination
ciąg.
Przykład: funkcja C strcat ()
#include #include int main() ( char str1(100) = "This is ", str2() = "programiz.com"; // concatenates str1 and str2 // the resultant string is stored in str1. strcat(str1, str2); puts(str1); puts(str2); return 0; )
Wynik
To jest programiz.com programiz.com
Uwaga: Kiedy używamy strcat()
, rozmiar ciągu docelowego powinien być wystarczająco duży, aby przechowywać wynikowy ciąg. Jeśli nie, otrzymamy błąd segmentacji.