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.

[参考译文] MSP430FR2355:C 问题---如何将 UART 缓冲区传输到字符串文字进行比较?

Guru**** 2516200 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1164130/msp430fr2355-c-question------how-to-transfer-uart-buffer-to-a-string-literal-to-compare

器件型号:MSP430FR2355

您好...

我通过 UART 接收字符...我将字符填充到数组中... x 个数字后,我想将这些字符与字符串文字进行比较...不确定如何正确执行...我正在获取我的传入数组并添加'\0',然后尝试使用 strcpy 进行比较...编译器不喜欢我 执行此操作。  具有 C 语言技能的人能否解释我做了什么错???

static char NMEA[30], NMEAstring[5]; //only visible to gps.c

uint8_t GPSMssgParser(gpsMssg_s *p)
{
    uint8_t err = 0;

    static uint8_t i = 0;

     NMEA[i] = p->gps.pSysCommsA->UCAxRXBUF;
     i++;

     if (i == 5)
     {
         NMEA[6] = '\0';
         strncpy(NMEAstring[0], NMEA[0], 6);
     }

     if (NMEAString[0] == "$GNRMC")
     {
         P1OUT ^= BIT0;
     }


     return err;
}

警告和错误  

"../driver/source/gps.c", line 35: warning #169-D: argument of type "char" is incompatible with parameter of type "char *__restrict__"
"../driver/source/gps.c", line 35: warning #169-D: argument of type "char" is incompatible with parameter of type "const char *__restrict__"
"../driver/source/gps.c", line 38: error #20: identifier "NMEAString" is undefined

谢谢

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

    NMEAstring[0]是数组的第一个字符、而 strncpy 需要一个地址。 使用 NMEAstring[0]或 NMEAstring。

    至于比较,编译器不知道如何执行该操作,但 strcmp()确实执行了该操作。