All submissions

Implement Custom strcpy function

Code

#include<stdio.h>
void custom_strcpy(char *dest, const char *src) {
    const char *p1 = src;
    char *p2 = dest;

    for (int i=0;src[i];i++) {
        *p2 = *p1;
        p1++;
        p2++;
    }
    *p2 = '\0';
}


int main() {
    char src[101];
    char dest[101];
    fgets(src, sizeof(src), stdin);

    // Remove newline
    int i = 0;
    while (src[i] != '\0') {
        if (src[i] == '\n') {
            src[i] = '\0';
            break;
        }
        i++;
    }

    custom_strcpy(dest, src);
    printf("%s", dest);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

firmware

Expected Output

firmware