我使用Valgrind工具调试了我的代码。它在此功能中显示此错误。我在下面给出了错误和我的功能。我不知道这里有什么问题?我该如何纠正它? 我的错误是。未初始化的值是由堆栈分配创建的
未初始化值由堆栈分配在0x80996D7创建: cdtojd(的std :: string常量&)
我的代码。
double cdtojd(const string &cdate);
double cdtojd(const string &cdate)
{
int dd,mm,yy;
int y,m;
double jd=0;
//mm = atoi(cdate.substr(0,2).c_str());
//dd = atoi(cdate.substr(2,2).c_str());
//yy = atoi(cdate.substr(4,4).c_str());
sscanf(cdate.c_str(),"%2d%2d%4d",&mm,&dd,&yy);
//cout<<mm<<"..."<<dd<<"...."<<yy<<endl;
y = (yy - 1900) * 372;
m = (mm-1) * 31;
jd = dd + m + y;
return jd;
}
您是否考虑检查sscanf()是否存在错误? – 2014-10-04 08:06:19
检查sscanf是否成功 – Igor 2014-10-04 08:06:59