C
collinm
hi
this is my code to analyse a file
void analyzeFilename()
{
char string[]="B_L2_HLD_GRN_NOR_Run_Counter.txt";
char *tokenptr;
char *seperators="_";
tokenptr = strtok(string,seperators); /* get the first token
*/
while (tokenptr != NULL) /* while more tokens in
strng */
{
printf("\t%s\n",tokenptr); /* print first token */
tokenptr = strtok(NULL,seperators); /* get next token */
}
}
that work fine
now i want to compare the token string, i do:
void analyzeFilename()
{
char string[]="B_L2_HLD_GRN_NOR_Run_Counter.txt";
char *tokenptr;
char *seperators="_";
tokenptr = strtok(string,seperators); /* get the first token
*/
while (tokenptr != NULL) /* while more tokens in
strng */
{
printf("\t%s\n",tokenptr); /* print first token */
tokenptr = strtok(NULL,seperators); /* get next token */
if(strcmp(tokenptr,"HLD")==0)
printf("hold\n");
}
}
i get a segmentation fault
any idea?
this is my code to analyse a file
void analyzeFilename()
{
char string[]="B_L2_HLD_GRN_NOR_Run_Counter.txt";
char *tokenptr;
char *seperators="_";
tokenptr = strtok(string,seperators); /* get the first token
*/
while (tokenptr != NULL) /* while more tokens in
strng */
{
printf("\t%s\n",tokenptr); /* print first token */
tokenptr = strtok(NULL,seperators); /* get next token */
}
}
that work fine
now i want to compare the token string, i do:
void analyzeFilename()
{
char string[]="B_L2_HLD_GRN_NOR_Run_Counter.txt";
char *tokenptr;
char *seperators="_";
tokenptr = strtok(string,seperators); /* get the first token
*/
while (tokenptr != NULL) /* while more tokens in
strng */
{
printf("\t%s\n",tokenptr); /* print first token */
tokenptr = strtok(NULL,seperators); /* get next token */
if(strcmp(tokenptr,"HLD")==0)
printf("hold\n");
}
}
i get a segmentation fault
any idea?