strcpy using pointers

前端 未结 7 1067
无人及你
无人及你 2021-01-13 11:29

I\'m trying to write strcpy on my own using pointers and I get an error during runtime.

void str_cpy(char **destination, const char *source) {
//    char *s1         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 12:32

    #include
    void main()
    {
    
        void mystrcpy(char *,char *);
    
        char s1[100],s2[100];
        char *p1;
        char *p2;
        p1=s1;
        p2=s2;
        printf("Enter the string to copy to s2...?\n");
        scanf("%s",p1);
    
    
        mystrcpy(p2,p1);
    
        printf("S2 after copying = %s",p2);
    
    }
    void mystrcpy(char *p2,char *p1)
    {
        while(*p1!='\0')
        {
            *p2=*p1;
            p2++;
            p1++;
        }
        *p2='\0';
    
    }
    

    Its my solution..Simple to understand..

提交回复
热议问题