1
int main()
{
printf("Welcome to the temperature control program:\n");
    printf("enter the ascii temperature characters");
    printf("enter the ascii characters of an euipment name with + or - and followed by a integer value");
    printf("type character terminated by carriage return");

    char tbuffer [tbuffer_length];
    printf("enter the temperature value");
    scanf("%7c", tbuffer);
    char *t;
    t = fgets (tbuffer, tbuffer_length, stdin );
    if(tbuffer[0] = 'A')
    {

    }
    if (tbuffer[0] = 'B')
    {

    }
    if (tbuffer[0] = 'C')
    {

    }

return 0;
}

この場合、ユーザーは文字列値を入力します (例: char buffer[7]= {'A', '+', '2', '5', '.','5','\r'} ) この文字列を A に機器 A または B に機器 B があると解釈する方法、+25.5 には温度値 (この温度値を整数に変換したい) とキャリッジ リターンがあります。これを解釈して整数に変換した後、インターフェイスを介して送信する必要があります(インターフェイスを介して送信する方法を知っています)。解釈のアイデアを教えてください。

4

2 に答える 2

0

== 演算子を使用して値を比較する

int main()
{
printf("Welcome to the temperature control program:\n");
    printf("enter the ascii temperature characters");
    printf("enter the ascii characters of an euipment name with + or - and followed by a integer value");
    printf("type character terminated by carriage return");

    char tbuffer [tbuffer_length];
    printf("enter the temperature value");
    scanf("%7c", tbuffer);
    char *t;
    t = fgets (tbuffer, tbuffer_length, stdin );
    if(tbuffer[0] == 'A')
    {

    }
    if (tbuffer[0] == 'B')
    {

    }
    if (tbuffer[0] == 'C')
    {

    }

return 0;
}
于 2013-05-28T14:31:17.830 に答える