嵌入式 linux读取按行读写文本文件

  1. #include <</SPAN>stdio.h>
  2. #include <</SPAN>unistd.h>
  3. #include <</SPAN>fcntl.h>
  4. #include <</SPAN>string.h>
  5. #include <</SPAN>malloc.h>
  6. #include <</SPAN>stdlib.h>


  7. typedef struct item_t {
  8. char *key;
  9. char *value;
  10. }ITEM;

  11. /*
  12. *去除字符串右端空格
  13. */
  14. char *strtrimr(char *pstr)
  15. {
  16. int i;
  17. i = strlen(pstr) - 1;
  18. while (isspace(pstr[i]) && (i >= 0))
  19. pstr[i--] = '\0';
  20. return pstr;
  21. }
  22. /*
  23. *去除字符串左端空格
  24. */
  25. char *strtriml(char *pstr)
  26. {
  27. int i = 0,j;
  28. j = strlen(pstr) - 1;
  29. while (isspace(pstr[i]) && (i <</SPAN>= j))
  30. i++;
  31. if (0<</SPAN>i)
  32. strcpy(pstr,&pstr[i]);
  33. return pstr;
  34. }
  35. /*
  36. *去除字符串两端空格
  37. */
  38. char *strtrim(char *pstr)
  39. {
  40. char *p;
  41. p =strtrimr(pstr);
  42. return strtriml(p);
  43. }


  44. /*
  45. *从配置文件的一行读出key或value,返回item指针
  46. *line<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值