Strcmp不将数组与字符串“ abc”进行比较

时间:2018-10-28 13:55:02

标签: c

我正在尝试使用strcmp函数将包含月份名称(例如“ dec”,“ jan”等)的数组与字符串“ dec”进行比较,但无法正常工作 该程序的目的是将日期相加, 2018年12月12日,结果应显示为1 + 2 + 1 + 2 + 2 + 0 + 1 + 8 = 17

export default () => (

  <Switch>
    <Route exact path="/abcd" component={Locked} />

    {/* <Route onEnter={requireAuth}> */}
    <Master  >

      < Switch >
        <Route exact path="/abcdefg"  component={abcdefg}/> 
      </ Switch>

    </Master>
    {/* </Route>;  */}

    <Route exact path="*" components={NotFound} />
  </Switch>

);

1 个答案:

答案 0 :(得分:1)

b的数组大小需要增加,并使用空终止符,如下所示:

char b[4]; // need size 4 to hold "dec"
/* other codes */
b[k] = '\0'; // put null terminator 
printf("\n%d\n", sum);
printf("%s", b); // you can avoid the loop and use %s