ADVERTISEMENT
ADVERTISEMENT

C - Implement String Copy using Pointer (strcpy using pointer) using C Program.


IncludeHelp 02 August 2016

In this code snippet, we will learn how to implement strcpy() (String Copy) using Pointers in C language.

C Code Snippet - Implement String Copy using Pointers through C Program

//C - Implement String Copy using Pointer (strcpy using pointer) using C Program.
#include <stdio.h>

//function to copy string using pointer
//Author: www.includehelp.com

void string_copy(char* target, char* source){
	while(*target=*source){
		*target++;
		*source++;
	}
}

int main(){
	char srcString[30]="Hello World!";
	char trgtString[30]={0};
	
	//copy string
	string_copy(trgtString, srcString);
	printf("Source String: %s\n",srcString);
	printf("Target String: %s\n",trgtString);
	
	return 0;
}
    Source String: Hello World!
    Target String: Hello World!

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.