引用请注明出处:http://blog.csdn.net/int64ago/article/details/7416985
话不多说,先来看个例子:
#include <stdio.h>
#include <string.h>
void print_tokens(char *line)
{
static char whitespace[] = " ";
char *token;
for(token = strtok(line,whitespace); token != NULL;
token = strtok(NULL,whitespace)){
printf("Next token is %s\n",token);
}
}
int main(int argc, char *argv[])
{
char line[] = "we are friends !! \n";
//char *line = "we are friends !!";
int len = strlen(line);
print_tokens(line);
int i;
for(i = 0; i != len; ++i){
if(line[i])