Implement Custom strcpy function

Code

#include <stdio.h>

void custom_strcpy(char *dest, const char *src) {
    // Your logic here
   int len = 0;
   while(*src != '\0')
   {
    src++;
    len++;
   }
   //printf("%d",sizeof(src));
   src=src-len;
   for(int i = 0 ; i < len+1; i ++)
   {
     *(dest + i) = *(src+i);
   }
    dest[len] = '\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

 

 

 

Upvote
Downvote
Loading...

Input

firmware

Expected Output

firmware