C and C++ - Strcpy - String Copy Example

<<Previous

Next >>





strcmp() - String Compare        strcat() - String Concatenate        strlen() - String Length



strcpy in C and C++ Programming - Syntax

strcpy() function copies the entire content from one string to another string.

Syntax:
	char *strcpy(char *dest, const char *src)

For example:

	strcpy(s2,s1)-->copies content from s1 into s2.

Example program using strcpy()

#include<stdio.h>

#include<string.h>


main()
{
  char source[]={’W’,‘E’,‘L’,‘C’, ‘O’,‘M’,‘E’};
  char dest[10]=" ";

  printf("The source string is %s",source);
  strcpy(dest,source);
  printf("The destination string after copy %s",dest);
  return(0);
}

Output:

The source string is WELCOME
The destination string after copy WELCOME

strlwr() - String Lower        strncat() - String n Concatenation       

strncmp() - String n Compare        strncpy() - String n Copy






<< Previous

Next >>




strcat() - String Concatenation        strcmp() - String Compare


strcpy() - String Copy        strlen() - String Length




C and C++ - Strcpy - String Copy Example

<<Previous

Next >>





strcmp() - String Compare        strcat() - String Concatenate        strlen() - String Length



strcpy in C and C++ Programming - Syntax

strcpy() function copies the entire content from one string to another string.

Syntax:
	char *strcpy(char *dest, const char *src)

For example:

	strcpy(s2,s1)-->copies content from s1 into s2.

Example program using strcpy()

#include<stdio.h>

#include<string.h>


main()
{
  char source[]={’W’,‘E’,‘L’,‘C’, ‘O’,‘M’,‘E’};
  char dest[10]=" ";

  printf("The source string is %s",source);
  strcpy(dest,source);
  printf("The destination string after copy %s",dest);
  return(0);
}

Output:

The source string is WELCOME
The destination string after copy WELCOME

strlwr() - String Lower        strncat() - String n Concatenation       

strncmp() - String n Compare        strncpy() - String n Copy






<< Previous

Next >>






strncat() - String n Concatenation        strlwr() - String Lower       

strncmp() - String n Compare       strncpy() - String n Copy