标题:为什么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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-456427-1-1.html




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

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