Skip to content

Instantly share code, notes, and snippets.

@meerasndr
Created February 4, 2021 07:31
Show Gist options
  • Save meerasndr/ad5653185fbb358c6dc85e2c216a3f72 to your computer and use it in GitHub Desktop.
Save meerasndr/ad5653185fbb358c6dc85e2c216a3f72 to your computer and use it in GitHub Desktop.
//This uses char* pointers. The same thing can be done using character arrays as well.
#include<stdio.h>
#include<stdlib.h>
void mystrcpy(char* first, char* second){
while(*first != '\0'){
*second = *first;
first++;
second++;
}
}
int main(void){
char *first = "hello";
char *second = malloc(sizeof(char*));
mystrcpy(first, second);
printf("The copied string is %s\n", second);
free(second);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment