Split a string into several and copy them to the pointer array

#include <stdio.h>
#include <string.h>
#include <memory.h>
int main(int argc, char *argv[])
{
    int i = 1;
    char str[40] = "1111@22222#333333$4444444^55555555";
    char buf[40] = {0};
    strcpy(buf, str);
    char *temp = strtok(buf,"@#$^");
    char *p[5] = {0};
    p[0] = temp;
    printf("p[0]=%s\n", *&p[0]);//*&p[0]=p[0]
    while (temp && i < 5) {
        temp = strtok(NULL, "@#$^");
        p[i] = temp;//注意这里strcpy和memcpy都不行
        printf("p[%d]=%s\n", i, p[i]);
        i++;
    }
}

 

Guess you like

Origin blog.csdn.net/cp_srd/article/details/83688907