c - 数据类型if语句不识别数值

时间:2017-03-13 12:07:17

标签: c types

我试图在串行控制台上输入10个字符,并将它们添加到名为buffer的数组中。字符必须是以下0,1,L或S之一。

它说1和0无效但是' L'和' S'好的我的数据类型错了吗?

由于

int main(void)
{
int ch;

char buffer[10] = "";

for (int i = 0; i < 10; i++) {

    putstring("Enter command\r\n");
    ch = getcharacter();

    if ((ch == '0') || (ch == '1') || (ch == 'L') || (ch == 'S')) {

        buffer[i] = ch;
        putstring(ch);
    }
    else {
        putstring("Input not valid");
        break;
    }
}
}


void putstring(char *str) {

    /*Needs an error check such as timeout or check for NULL string*/
    const uint32_t transmit_ready = 1 << 6;

    while (*str != '\0') {

        if ((*uart_status_reg)  & transmit_ready) {

            *uart_txdata_reg = *str;
            str++;
        }
    }

}

int getcharacter(void) {

    uint8_t c = 0;
    const uint32_t recieve_ready = 1 << 7;

    //disable interrupt for a read ready
    *uart_control_reg = 0;

    while (1) {
        //check if RRDY bit is set
        if ((*uart_status_reg) & recieve_ready) {
            c = *uart_rxdata_reg;
            break;
        }
    }
    return ((int) c);
}

0 个答案:

没有答案