打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
关于指针位置还原的小程序(YC)
#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;
}

运行结果:


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C语言一维数组初步学习笔记
请用代码写一个算法测试回环字符串函数
PHP中GBK和UTF8编码处理 - PHP教程|PHP5|PEAR|框架 - Power...
指针数组和数组指针
Sizeof与Strlen的区别与联系
让你的 C 程序更有效率的 10 种方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服