Copy struct to struct in C

前端 未结 7 1723
北荒
北荒 2020-11-27 14:06

I want to copy an identical struct into another and later on use it as a comparance to the first one. The thing is that my compiler gives me a warning when Im doing like thi

相关标签:
7条回答
  • 2020-11-27 14:57

    Also a good example.....

    struct point{int x,y;};
    typedef struct point point_t;
    typedef struct
    {
        struct point ne,se,sw,nw;
    }rect_t;
    rect_t temp;
    
    
    int main()
    {
    //rotate
        RotateRect(&temp);
        return 0;
    }
    
    void RotateRect(rect_t *givenRect)
    {
        point_t temp_point;
        /*Copy struct data from struct to struct within a struct*/
        temp_point = givenRect->sw;
        givenRect->sw = givenRect->se;
        givenRect->se = givenRect->ne;
        givenRect->ne = givenRect->nw;
        givenRect->nw = temp_point;
    }
    
    0 讨论(0)
提交回复
热议问题