Home C-tutorials C String Copy



C String Copy
Posted on: February 6, 2009 at 12:00 AM
In this section, you will learn how to copy the string in C. You can see in the given example, two string variables st1 and st2 are created.

C String Copy

     

In this section, you will learn how to copy the string in C. You can see in the given example, two string variables st1 and st2 are created. A string is passed to the st1. Then we have used the library function strcpy() provided by the header file <string.h> that will copy the specified string from st1 to st2.

Here is the code:

StringCopy.c

 

 

 

 

 

 

 

 

#include <stdio.h>
#include <conio.h>
#include <string.h>
int main() {
  char st1[]="Hello World";
  char st2[20];
  clrscr();
  strcpy(st2, st1);
  printf("st1= %s\n st2= %s\n", st1, st2);
  getch();
  return 0;
}

Output will be displayed as:

STRING~1.EXE

Download Source Code:

Related Tags for C String Copy:
cstringvariablesiocopyvariableriathiscreateexampletolearnexameareilsectioncanvarinmtrcaeshowxaxampscreatedeeatisllivmpleaandarcopstrvatwssriringthstabablpleplndono


More Tutorials from this section

Ask Questions?    Discuss: C String Copy  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.