C语言中一个小问题

#include <stdio.h>
#include <string.h>


int main()
{
   char send_buf[] = "Hello,client, This is what I want to send you";
   char recv_buf[] = "Really? I don't want to recv it anymore,so don't send it to me";


   if(strlen(send_buf) > strlen(recv_buf))
   {
        printf("the length of send_buf is longer than recv_buf\n");
   }
   else
   {
        printf("the length of recv_buf is longer than send_buf\n");
   }




   if(strlen(send_buf) - strlen(recv_buf) > 0)
   {
        printf("the length of send_buf is longer than recv_buf\n");
   }
   else
   {
        printf("the length of recv_buf is longer than send_buf\n");
   }
   return 0;
}
输出结果:
the length of recv_buf is longer than send_buf
the length of send_buf is longer than recv_buf


在网路程序中使用的是第二种写法,结果一直不是想要的,好奇怪,然后写了这个小东西测试下。
在man strlen一下,知道其中的原因后。


再次写了个测试:
#include <stdio.h>
#include <stddef.h>


int main()
{
   size_t a = 10;
   size_t b = 15;
   size_t c = a - b;
   int d = (c-0)>0?1:0;
   printf("d=%d\n",d);
   return 0;
}
测试结果:
1


发出来分享下,回顾下基础的知识。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值