Skip to content

Instantly share code, notes, and snippets.

@kenOfYugen
Created March 16, 2016 18:24
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 kenOfYugen/df17dff58e567b2e1ac1 to your computer and use it in GitHub Desktop.
Save kenOfYugen/df17dff58e567b2e1ac1 to your computer and use it in GitHub Desktop.
String Copying in C
#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