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.

[参考译文] CCS/MSP430F5529:将字符串传递到函数中

Guru**** 2601915 points
Other Parts Discussed in Thread: MSP430F5529

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

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/628545/ccs-msp430f5529-passing-string-into-a-function

部件号:MSP430F5529

工具/软件:Code Composer Studio

好吧,我已经编程了一段时间了,但我在一台计算机上尝试过,结果都通过了,但在代码编写器上却没有。 它只通过了20个字符中的10个,values....it应该通过"12345678901234567890",但它只通过"0123456789"...

  

#include <msp430F5529.h>
#include <string.h>

CHAR StrBuffer[22];
int i;

void func(car *string_char;

内部主(无效)


WDTCTL = WDTPW | WDTHOLD;//停止看门狗计时器
strcpy (StrBuffer,"12345678901234567890"); //使用自定义字符串填充缓冲区
func (StrBuffer);//将其传递到一个简单函数
返回0;
}

void func(car *string_char)

i = sizeof(string_char);
}

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

    i = sizeof(string_char);

    使用strlen而不是sizeof。  另一个要考虑的技巧... 使用Code Composer Studio调试程序,在func中停止执行,然后查看string_char。

    谢谢,此致,

    -George

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    sizeof(string_char)只是指针的大小,您需要strlen()来获取函数中字符串的长度。
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好,
    哈哈! 我刚在一分钟前得出这一结论,并即将发表我自己的答案!

    谢谢大家。