Created
March 16, 2016 18:24
-
-
Save kenOfYugen/df17dff58e567b2e1ac1 to your computer and use it in GitHub Desktop.
String Copying in C
This file contains 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" | |
int lengthOf(char input[]) { | |
int i; | |
for (i = 0; input[i] != '\0'; i++); | |
return i; | |
} | |
void copyString(char input[], char output[]) { | |
int i; | |
for (i = 0; i < lengthOf(input); i++) { | |
output[i] = input[i]; | |
} | |
} | |
int main(void) { | |
char string1[] = "keiker"; | |
char string2[lengthOf(string1)]; | |
copyString(string1, string2); | |
printf("%s\n", string2); | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment