Help using "strtok" in C

I need to tokenize a string and have an array of pointers point to each word. If somebody could please help me I would really appreciate it.

so if i have....


int i=0;
char sample[100]= "This is my sample string";
char * dptr= sample; //dptr points to sample string
char * Array[100]; //declare an array of pointers

while(dptr != NULL){
Array[i]= strtok(dptr, " ' ' ");
Array[i]= strtok(NULL, " ' ' ");
printf("\n%s", Array[i]);
i++;
}


// i need the loop to print..


This
is
my
sample
string

// so that
Array[0]= This
Array[1]= is
Array[2]= my
....







Last edited on
Topic archived. No new replies allowed.