C split a char array into different variables

后端 未结 7 966
不思量自难忘°
不思量自难忘° 2020-12-03 08:31

In C how can I separate a char array by a delimiter? Or is it better to manipulate a string? What are some good C char manipulation functions?

相关标签:
7条回答
  • 2020-12-03 09:08

    One option is strtok

    example:

    char name[20];
    //pretend name is set to the value "My name"
    

    You want to split it at the space between the two words

    split=strtok(name," ");
    
    while(split != NULL)
    {
        word=split;
        split=strtok(NULL," ");
    }
    
    0 讨论(0)
提交回复
热议问题