Implement a String Copy function in C – which is commonly asked during the coding interview for embeded programming jobs. In C, we use char * to represent the string (char array). And a string is ended with \0 character.
C Implementation of Copy String
The following C function takes a source and copy its content to the pre-allocated target. If the target does not have enough space pre-allocated, a memory access violation will occur.
void copyString(char *target, char *source) {
while (*source != '\0') {
*target = *source;
source ++;
target ++;
}
*target = '\0';
}
–EOF (The Ultimate Computing & Technology Blog) —
188 wordsLast Post: Math Algorithm to Count the Number of Palindromes Made From Letters
Next Post: Shortcuts and Tips for Mac Beginners (Switching from Windows/Linux)
