BeginnersBook.in

Programming For Geeks

  • Home
  • All Tutorials
    • Learn C
    • Learn Python
  • Programs
    • Java Programs
    • C++ Programs
    • C Programs
  • Algorithms
    • Sorting
  • MCQ’s
    • MySQL
    • Operating System
  • WordPress
    • Genesis Pro Themes
    • Blogs
  • Tools
    • Direct Download Link Generator
    • HTML Compiler
  • How to
    • Web Examples
  • Write For Us

C – strcat() function

June 3, 2018 By Mr. Robot

strcat() is a useful string library function, which concatenates one string to another.

To concatenate is to glue one or more pieces of data together or to connect one or more links together.

Syntax

Following is the syntax of strcat() function:

1
char *strcat(char *dest, const char *src)

Parameters

dest − This is pointer to the destination array, which should contain a C string, and should be large enough to contain the concatenated resulting string.

src − This is the string to be appended. This should not overlap the destination.

Example of strcat()

Let’s see the simple example to concatenate first string with another:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<stdio.h>  
#include<string.h>    
int main()
{    
    char ch[20]={'h', 'e', 'l', 'l', 'o', '\0'};    
    char ch2[20]={'w', 'o', 'r', 'l', 'd', '\0'};    
    
    strcat(ch,ch2);    
    
    printf("Value of first string is: %s",ch);    
    return 0;    
}
When you run above program, the output will be following:
1
Value of first string is: helloworld

String Manipulation Functions

Few commonly used string handling functions are discussed below:

String FunctionsDescription
strlen()Calculates the length of string
strcat()Concatenates(joins) two strings
strncat()Appends a portion of string to another
strcpy()Copies a string to another string
strncpy()Copies number of characters of one string to another
strcmp()Compares two strings
strncmp()compares at most the first n bytes of str1 and str2.
strchr()Returns pointer to first occurrence of char
strrchr()Return last occurrence of given character in a string is found
strstr()Returns pointer to the first occurrence of the string
strdup()Duplicates the string
strndup()Similar to strdup(), but copies at most n bytes.
strerror()Returns the error message
strtok()Tokenizing given string using delimiter
strcoll()Compares first string with another.

Filed Under: C Tutorial

Related Posts

  • C library function fscanf() – Reading a file
  • if-else statement in C
  • C library function rewind()

Recent Posts

  • Download Grand Theft Auto: Vice City Audio File | Highly Compressed
  • Grand Theft Auto: Vice City Game Download For PC | Full Setup
  • SQL SHOW DATABASES Statement
  • Direct view storage Tube (DVST) in Computer Graphics
  • CRT Color Monitor in Computer Graphics

C Tutorial

  • C - Home
  • C - Introduction
  • C - History
  • C - Features
  • C - Limitations
  • C - Environment Setup
  • C - First Program
  • C - Input & Output
  • C - Variables
  • C - Identifiers
  • C - DataTypes
  • C - Comments
  • C - Keywords
  • C - Operators
  • C - Typecast Operator
  • C - Sizeof Operator
  • C - Escape Sequence
  • C - Constants

C Control Statements

  • C - Simple if
  • C - if-else
  • C - else-if
  • C - Nested if-else
  • C - Switch

C Loops

  • C - For loop
  • C - While loop
  • C - do-while loop
  • C - Break Statement
  • C - Continue Statement
  • C - goto Statement

C Functions

  • C - Functions
  • C - Call by value
  • C - Call by reference
  • C - Storage Classes

C Array

  • C - Arrays
  • C - 2-D Array
  • C - Array to function

C Pointers

  • C - What is Pointer
  • C - Pointer to Pointer
  • C - Pointer Arithmetic

C Strings

  • C - What is Strings
  • C - String Functions

C Structure

  • C - What is Structure
  • C - Array of Structure
  • C - Nested Structure
  • C - Using typedef
  • C - Pointers to Structure

C Union

  • C - What is Union
  • Structure vs Union

C File Handling

  • C - File Input/Output

C Advance

  • C - Command Line Arguments

More…

  • C - Enumeration
  • C - Examples

Copyright © 2019 - BeginnersBook.in - All Right Reserved || Sitemap