struct DISPLAY_INFO * display_info;
typedef struct DISPLAY_INFO;
DISPLAY_INFO display_info_2;
必须将diplay_info_2复制到display_info。我怎么能用memcpy来做呢。
答案 0 :(得分:1)
Iff(当且仅当) display_info指向有效的内存区域,您可以写
memcpy(display_info, &display_info_2, sizeof(DISPLAY_INFO));
e.g。
#include <stdio.h>
typedef struct DISPLAY_INFO{
int val;
} DISPLAY_INFO;
int main() {
DISPLAY_INFO *display_info;
display_info = (DISPLAY_INFO*)malloc(sizeof(DISPLAY_INFO));
DISPLAY_INFO display_info_2; // The object to be copied
display_info_2.val = 42;
memcpy(display_info, &display_info_2, sizeof(DISPLAY_INFO));
printf("%d", display_info->val);
free(display_info);
return 0;
}
答案 1 :(得分:0)
你可以这样做:*display_info = display_info_2
。