【问题标题】:Unhandled Exception when using itoa使用 itoa 时出现未处理的异常
【发布时间】:2013-06-04 06:01:20
【问题描述】:

以下是我的代码的一部分。我不确定它有什么问题,因为当我调试此代码时,我收到以下错误:

client0.exe 中 0x60e8144c (msvcr90d.dll) 处的未处理异常: 0xC0000005:访问冲突写入位置0x00000000。

这是在 itoa 行中的某个地方。

代码:

   int num =  LOWORD (lparam);
   char *number = NULL,*detail = NULL;
   (char*)itoa(num,number,10);

【问题讨论】:

标签: c windows debugging error-handling itoa


【解决方案1】:

您必须将有效的初始化指针传递给itoa()

【讨论】:

  • 你的意思是我必须先用一些值初始化 *number 吗? :(
  • @AyeshaHassan 不,number 必须指向已分配内存的有效内存位置。
  • 谢谢,我现在明白了:)
【解决方案2】:

number 是指针,您还没有为它分配内存。然后尝试写入它。

更新它以使用数组或使用malloc分配内存

int num =  LOWORD (lparam);
char number[20],*detail = NULL;
(char*)itoa(num,number,10);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多