M
manochavishal
Hi
I am writing a Program
in which i get input as
#C1012,S,A#C1013,S,U
I want to get C1012,S,A using strtok and then pass this to function
CreateCopies
which will further strtok this (C1012,S,A) and store the required
values.
Now here is the piece of that code:
#define DELIM2 #
char * field;
char fieldcopy[20];
/*Here i have input as #C1012,S,A#C1013,S,U*/
field = strtok(NULL,DELIM2);
while(field != NULL)
{
strcpy(fieldcopy,field);
CreateCopies(copy,fieldcopy,NoCopies);
field = strtok(NULL,DELIM2);
printf("Field in CreateVideo is %s\n",field);
}
1.Now if I call CreateCopies the strtok doesn't tokenize till the end.
I get to call CreateCopies
only once.
2.But if i comment the CreateCopies call, it does tokenize till the end
and prints the rrquired vales.
In the first case the second time i call strtok 'field' gets a value of
NULL instead it should get the second token.
Why this behaviour???
I am writing a Program
in which i get input as
#C1012,S,A#C1013,S,U
I want to get C1012,S,A using strtok and then pass this to function
CreateCopies
which will further strtok this (C1012,S,A) and store the required
values.
Now here is the piece of that code:
#define DELIM2 #
char * field;
char fieldcopy[20];
/*Here i have input as #C1012,S,A#C1013,S,U*/
field = strtok(NULL,DELIM2);
while(field != NULL)
{
strcpy(fieldcopy,field);
CreateCopies(copy,fieldcopy,NoCopies);
field = strtok(NULL,DELIM2);
printf("Field in CreateVideo is %s\n",field);
}
1.Now if I call CreateCopies the strtok doesn't tokenize till the end.
I get to call CreateCopies
only once.
2.But if i comment the CreateCopies call, it does tokenize till the end
and prints the rrquired vales.
In the first case the second time i call strtok 'field' gets a value of
NULL instead it should get the second token.
Why this behaviour???