Skip to content

Instantly share code, notes, and snippets.

@joegasewicz
Last active November 25, 2022 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joegasewicz/bd0f75c1b34210293a4ce8e01d978a09 to your computer and use it in GitHub Desktop.
Save joegasewicz/bd0f75c1b34210293a4ce8e01d978a09 to your computer and use it in GitHub Desktop.
Pointer & Strings
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