by Dinesh Thakur Category: C Programming (Pratical)

The program implements the Copy string to another string. The inner function “stcpy” takes 2 string pointers as arguments. “copystr” pointer type function declared and pointer type char variable declare. On next move the argument written “I am Dinesh Thakur” in the variable char pointer type and array type string variable. The required function used “cpystr”.

In the next move void copystr() and pointer type two variable dest ,src. While condition src!=0 then dstn=src then the string will be copied in dest then return the result as copied string.
Problem Statement:- 
This program User asks to Copy String from one To another string with the Help of Pointer.

  1. Declare pointer type variable.
  2. Using While Statement.
  3. Display result on the screen.

This C program is successfully compiled and run on a System. Output is shown below

#include<stdio.h> 
void copystr(char*,char*);
void main()
{
             char*str1="I am Dinesh Thakur";
             char str2[30];
             clrscr();
             copystr(str2,str1);
             printf("\n %s",str2);
             getch();
 }
            void copystr(char *dest,char *src)
       {
                while(*src!='\0')
                *dest++=*src++;
                *dest='\0';
                return;
       }
 
Output :
 
I am Dinesh Thakur
Related Articles on C Programming



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.