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!




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.