小编Adn*_*bir的帖子

仅比较数组中的一个char

我是C的新人

这是我的代码

#include <iostream>
#include <string.h>
using namespace std;

int main() {
char time[20];
       scanf("%s",time);

       // command and "hello" can be less than, equal or greater than!
       // thus, strcmp return 3 possible values
       if (strcmp(time, "PM") == 0)
       {
          printf("It's PM \n");
       }


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

假设我在下午12:13:14输入

我想知道它是上午还是下午.但上面的代码只发现整个char数组是否为"PM".我看过其他帖子,我无法理解它们.

c++ c++14

-1
推荐指数
1
解决办法
98
查看次数

标签 统计

c++ ×1

c++14 ×1