第0步:整理格式--Strtok()函数

#include<stdio.h>
#include<string.h>

typedef unsigned char  uint8_t;
typedef unsigned short uint16_t;
int main(void)
{

    char buf[]="hello@boy@this@is@heima";
    char*temp = strtok(buf,"@");
    char *arr[100]={0};
    char i=0;
    while(temp)
    {
    	arr[i++]=temp;
        printf("%s ",temp);
        temp = strtok(NULL,"@");
    }
    printf("\n");
    for(i=0;i<10;i++)
    	printf("%s\n",arr[i] );
    return 0;
}

参考https://www.cnblogs.com/Bob-tong/p/6610806.html

改动一下:预留问题为什么现在不能sprintf???

#include<stdio.h>
#include<string.h>
typedef unsigned char  uint8_t;
typedef unsigned short uint16_t;


char buf[]={"00 2E BE 01 00 01 00 00 00 00 34 54 9A 4E 3E 4E \
  41 13 10 FC 99 06 01 74 5B 10 D5 DD 12 01 DD D1 \
  FE 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 \
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
  00 00 00 00 00 01 00 B4 2A 00 00 00 00 00 00 00 \
  00 00 00 00 00 00 00 00 00 00 00 00 00 00"};

int main(void)
{
    char *temp = strtok(buf," ");
    char *before[112]={0};
    char i=0;
    while(temp)
    {
    	before[i++]=temp;
        temp = strtok(NULL," ");
    }
    printf("\n");
    for(i=0;i<100;i++)
    {
    	printf("0x");
    	printf("%s",before[i] );
		printf(", ");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42381351/article/details/81669261