您的位置:首页 > 其它

Bugs Bugs

2013-12-06 11:26 211 查看
 

/***********Bug1*****************************************************************************/
int amount, curAmount, totalAmount;
CString str;
amount = atoi(X);
curAmount = XX;
totalAmount = XXX;
str.Format( "%d %d %d", amount, curAmount, totalAmount ); //1 这里有可能会出错,无法通过,因为某处无法转换

char cBuf[256] = { 0 };
sprintf( cBuf, "%d %d %d", amount, curAmount, totalAmount ); //2 OK

/***********Bug2*****************************************************************************/
int GetMoney( int &money )
{
int cash;

cash = 10000;
money = cash;
}

int myMoney;
GetMoney( myMoney );
//use myMoney  //这里会出错,因为引用了局部变量
/***********Bug3*****************************************************************************/
//在字符串拷贝的时候

struct PkgStruct //报文格式
{
char cActive[1];	//0: Not Active 1: Active
char cMakeCardSn[20];
};

strcpy( pSt1->cActive, "1" );  //会使cMakeCardSn[0]有一个空字符0

strncpy( pSt1->cActive, "1", sizeof( pSt1->cActive ) ); //这样OK

//strcpy会把字符串末尾的'\0'同时拷贝的,而当函数strlen发现'\0'即停止计算了,sizeof()则给出数组原先定义的大小


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: