分享

关于指针位置还原的小程序(YC)

 champion_xu 2012-04-22
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char str[100]="LEDNO=1&STATUS=ON&s",tmp[25],tmp2[25];
    char *t="led1off",*s="ed1off";
    int i=0,length,position;

    printf("%s\n",t);
    position = t;//保护现场,保存指针位置
    t++;
    printf("%s\n",t);
    if(strcmp(s,t)==0)
    printf("equal\n");
    t = position;//还原指针位置
    printf("%s\n",t);
    printf("str length=%d\n",strlen(str));
    sscanf(str,"%[^&]",tmp);//遇到&就结束,只保存&之前的数据
    while(str[i+strlen(tmp)+1]!='\0') {
    tmp2[i]=str[i+strlen(tmp)+1];
    i++;
    }
    length = i;
    tmp2[length]='\0';
    i=0;
    printf("new str:%s,ilength=%d,strlength=%d\n",tmp2,length,strlen(tmp2));
    sscanf(tmp2,"%[^&]",tmp2);
    printf("new tmp:%s,length=%d\n",tmp2,strlen(tmp2));
    printf("%s,length=%d",tmp,strlen(tmp));
    return 0;
}

运行结果:


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多