Created
February 4, 2021 07:31
-
-
Save meerasndr/ad5653185fbb358c6dc85e2c216a3f72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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