zoukankan      html  css  js  c++  java
  • C语言strchr使用之Next查找和截断想要的字符串

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <pthread.h>
    #include <semaphore.h>
    #include <unistd.h>
    #include <signal.h>
    #include <string.h>
    
    
    static char pstring[] =  "Hello
    ";   // 这里不能是char*
    
    int main()
    {
        char tmp ;
        char* pstr = strchr(pstring,'l');
        printf("pstr is %s %p
    ",pstr,pstr);
    
        #if 0
        // 搜后面的
        pstr = strchr(pstr+1,'l'); // 是strchr不是strstr
        printf("next pastr is %s
    ",pstr);
        #endif //
    
        //需要He
        tmp = *pstr;
        printf("%c",tmp);
        pstr[0] = '';
        printf("length is %d
    ",strlen(pstring)+1);
        char* data = (char*)malloc(strlen(pstring)+1);
        if(data == NULL)
        {
          printf("malloc failure
    ");
          return -1;
        }
        printf("length is %d
    ",strlen(pstring)+1);
        strcpy(data,pstring);
        printf("data is %s
    ",data);
        *pstr = tmp;
        free(data);
    
        while(1);
        return 0;
    }
    

      

    一勤天下无难事。
  • 相关阅读:
    12.如何设置ulimit
    11.vim常用操作
    01Java jdk环境配置
    css
    Html
    day07 Class_field_method_反射
    JDBC
    Oracle day05 索引_数据去重
    Oracle day05 建表_约束
    Oracle day04 DML_事务_序列_视图_数据类型_DDL
  • 原文地址:https://www.cnblogs.com/nowroot/p/13660647.html
Copyright © 2011-2022 走看看