This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F2.8027万:将int转换为string- sprintf和Itoa不工作

Guru**** 2584355 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/654128/tms320f28027-converting-int-to-string--sprintf-and-itoa-not-working

部件号:TMS320F2.8027万

大家好,我正在尝试将int转换为string。

char *msg;
Itoa (5,msg); 

此外,当使用sprintf时,代码会编译,但会在该行执行块。 Sprintf是否应在平台上工作?  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Ray,

    按照代码的现状,您将遇到未定义的行为,因为您尚未初始化char* msg。 尝试初始化缓冲区:

    	
    char msg[5];
    itoa(5, msg); 

    请告诉我此解决方案是否适合您。

    谢谢!

    Taumer

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,Taumer,感谢您的帮助。

    使用上述代码时,程序无法编译,因为无法识别itoa()。 如此处所述,Itoa()  不能识别e2e.ti.com/.../148634。14.8634万。声明为stdlib.h。

     

     

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    雷,我很抱歉。 在包含stdlib.h后,此代码应该对您有效:

    字符消息[5];
    ltoa (5,msg); 

    前导字符是小写"L",而不是大写"i"。

    请告诉我这是否适合您。

    谢谢!

    Taumer