Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created July 17, 2011 16:09
Show Gist options
  • Save Superbil/1087732 to your computer and use it in GitHub Desktop.
Save Superbil/1087732 to your computer and use it in GitHub Desktop.
string copy
#include <stdio.h>
void printString(char *string)
{
int i;
for (i = 0; string[i] != '\0' ; i++) {
printf("%c",string[i]);
}
}
void strCopyArray(char des[], char src[])
{
int i = 0;
for (i = 0; src[i] != '\0' ; i++)
des[i] = src[i];
des[i] = '\0';
}
void strCopyPoint(char *des, char *src)
{
while (*src != '\0')
*des++ = *src++;
*des = '\0';
}
int main(int argc, const char *argv[])
{
char *src = "Hello World";
char out_point[12];
char out_array[12];
printf("Array copy function: ");
strCopyArray(out_array, src);
printString(out_array);
printf("\n");
printf("Point copy function: ");
strCopyPoint(out_point, src);
printString(out_point);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment