| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 492 人关注过本帖
标题:为什么memcpy(&calendar, cal, sizeof(CALENDAR))执行后就有数据错误呢,求 ...
取消只看楼主 加入收藏
smallkiss
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-8-16
收藏
 问题点数:0 回复次数:0 
为什么memcpy(&calendar, cal, sizeof(CALENDAR))执行后就有数据错误呢,求原因
#include<iostream>
using namespace std;

typedef struct
{
    int year;
    int month;
    int date;
    int hour;
    int minute;
    int second;
    int millisecond;
}CALENDAR;

//CALENDAR* getCalendar()
//{
//    CALENDAR *cal = (CALENDAR *)malloc(sizeof(CALENDAR));
//    cal->year = 2015;
//    cal->month = 8;
//    cal->date = 15;
//    cal->hour = 14;
//    cal->minute = 34;
//    cal->second = 23;
//    cal->millisecond = 123;
//    return cal;
//}
CALENDAR *getCalendar()
{
    CALENDAR cal ;
    cal.year = 2015;
    cal.month = 8;
    cal.date = 15;
    cal.hour = 14;
    cal.minute = 34;
    cal.second = 23;
    cal.millisecond = 123;
    return &cal;
}

int main()
{
    CALENDAR* calendar=NULL;
    CALENDAR* cal;
    cal = getCalendar();
#if 0
    calendar.year = cal->year;
    calendar.month = cal->month;
    calendar.date = cal->date;
    calendar.hour = cal->hour;
    calendar.minute = cal->minute;
    calendar.second = cal->second;
    calendar.millisecond = cal->millisecond;
#endif
    memcpy(calendar, cal, sizeof(CALENDAR));
    cout << calendar->year << " "
        << calendar->month << " "
        << calendar->date << " "
        << calendar->hour << " "
        << calendar->minute << " "
        << calendar->second << " "
        << calendar->millisecond << " "
        << sizeof(CALENDAR) << endl;
    system("pause");
    return 0;
}
搜索更多相关主题的帖子: calendar include return minute second 
2015-08-16 12:56
快速回复:为什么memcpy(&calendar, cal, sizeof(CALENDAR))执行后就有数据错误呢 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved