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.
- Declare pointer type variable.
- Using While Statement.
- 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