Last active
November 25, 2022 21:23
-
-
Save joegasewicz/bd0f75c1b34210293a4ce8e01d978a09 to your computer and use it in GitHub Desktop.
Pointer & Strings
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
int main() | |
{ | |
char string1[] = "A string to be copied."; | |
char string2[50]; | |
copyStrong1(string2, string1); | |
return 0; | |
} | |
void copyStrong1(char to[], char from[]) | |
{ | |
int i; | |
for (i = 0; from[i] != '\0'; ++i) | |
to[i] = from[i]; | |
to[i] = '\0'; | |
} | |
void copyString2(char *to, char *from) | |
{ | |
for(; *from != '\0'; ++from, ++to) | |
*to = *from; | |
*to = '\0'; | |
} | |
void copyString3(char *to, char *from) | |
{ | |
while (*from) // the NULL character ('\0') is equal to 0, so jump out then. | |
*to++ = *from++; | |
*to = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment