strcpy

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
david_stelian
Junior
Junior
Posts: 21
Joined: 13 Sep 2014, 22:35
Judet: Dolj

strcpy

Post by david_stelian » 14 Apr 2018, 10:27

Salut!
Am o problema si anume vreau sa implementez functia strcpy, nu stiu de ce dar nu functioneaza.
Mai jos este codul :

Code: Select all

#include <stdio.h>
#include <stdlib.h>

char *strcpy(char *destination, char *source)
{
    char *saved = destination;
    while(*source != '\0')
    {
        *destination = *source;
        destination++;
        source++;
    }
    *destiation = '\0';
    return saved;
}

int main()
{
    char *ptr1 = "kjshdfoiswledkj";
    char *ptr2 = NULL;
    printf("\n The value of ptr1 is : %s\n", ptr1);
    printf("\n The value of ptr2 is : %s\n", ptr2);
    strcpy(ptr2, ptr1);
    printf("\n The value of ptr1 is : %s\n", ptr1);
    printf("\n The value of ptr2 is : %s\n", ptr2);
    return 0;
}



Post Reply