Created
July 17, 2011 16:09
-
-
Save Superbil/1087732 to your computer and use it in GitHub Desktop.
string copy
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
#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