Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Functions strcat and strncat

September 12, 2013 Posted by: GPA Views: 726 0 comments

Problem

Write simple program using strcat and strncat functions in C programming.

Solution

In this article, we discuss about two functions strcat and strncat and we'll write simple program using these functions. First of all you need include header file <string.h> for this program.

Declaration:

char *strcat( char * firstString , const char * secondString );

This function appends its second argument secondString to its first argument firstString.

char *strncat( char * firstString , const char * secondString , size_t n );

This function appends a specified number n of characters from the second string secondString to the first string firstString. Null character ('\0') is automatically appended to the firstString.

Example:

 




#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//main function
int main(int argc, char *argv[]){
printf("globalproganswer.com\n");
char firstString[]="Hello";//first parameter
char secondString[] = " world";//second parameter
char resultString[50]="";
printf("First string is: %s\n",firstString);
printf("Second string is: %s\n",secondString);
printf("\nResult of strcat function is: %s\n",strcat(firstString, secondString));//call function strcat
printf("\nResult of strncat function\n");
//show only 3 characters
printf( "The string in array resultString is: %s\n\n",strncat(resultString, firstString, 3) );//call function strncat
system("PAUSE");//delay
return 0;
}

Output

Function strcat and strncat

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe