小编Oma*_*ban的帖子

c中的字符串比较

我现在正在为fpga上的microblaze编写交流程序,我现在想检查一下我是否收到了消息,但是strncmp和strcmp不工作的唯一方法就是这样:

           char*as=malloc(sizeof(int));

    as=p->payload;
            if (*(as)=='o') {//first letter o
    if (*(as+1)=='k') {//second letter 
Run Code Online (Sandbox Code Playgroud)

但是,一旦我处理较长的文本,这将很难,所以任何好方法?我用这种格式试了strncmp:

         if (strncmp(as,"ok",2)==0)      //didnt work even changing 0 to 1 it just doesnt detectct it 
Run Code Online (Sandbox Code Playgroud)

c string char microblaze

2
推荐指数
1
解决办法
217
查看次数

标签 统计

c ×1

char ×1

microblaze ×1

string ×1