数据比较

[复制链接]
1993|2
 楼主| hlhfootbal 发表于 2012-5-25 15:14 | 显示全部楼层 |阅读模式
rc, TE, ST, code, se
  1. int convert_usercode_to_fpga(char *buf)
  2. {
  3. int i = 0;
  4. int j = 0;
  5. char tempa[RX_DATA_LEN] = {0};
  6. char tempb[RX_DATA_LEN] = {0};
  7. char *p;

  8. char usercode[][RX_DATA_LEN] = {
  9. {"gray"},
  10. {"colo"},
  11. {"ramp"},
  12. {NULL}
  13. };
  14. p = usercode;
  15. if (!buf)
  16. {
  17. return -1;
  18. }

  19. strcpy(tempa,buf);

  20. while (*(p + i))
  21. {
  22. strcpy(tempb,(const char *)(p + i));
  23. j = strcmp(tempa,tempb);

  24. if (j == 0)
  25. {
  26. return i;
  27. }
  28. i ++;
  29. }
  30. return -3;
  31. }


以上程序执行strcpy(tempb,(p + i));后就死了。
如果把二维数组usercode定义为char不会死,但是数组里德数据会被改写。

请问是什么原因?
谢谢!
sedatefire 发表于 2012-6-26 16:53 | 显示全部楼层
RX_DATA_LEN 是多长
buf传入的参数是什么,是否以'\0'结尾
代码贴全一点
sedatefire 发表于 2012-6-26 16:55 | 显示全部楼层
p = usercode;
靠,p依旧是个一维的指针哦,不要妄想编译器那么智能哦
您需要登录后才可以回帖 登录 | 注册

本版积分规则

133

主题

417

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部