0

I have been trying to make it so that placeholders like (%c) or (%d) are used as delimiters but whenever I try to it will also use the letter after the percent as a delimiter as well. Is there a way to make it so that both characters together are the delimiter and not so they are separate delimiters.

#include <stdio.h>
#include <string.h>

int main (void){

  char string[100];

  printf("Enter a string: ");

  fgets(string,sizeof(string),stdin);
  string[strlen(string)-1] = '\0';

  char seperator[] = " %c";

  char *token = strtok(string,seperator);

  while(token != NULL){

    printf("%s\n",token);
    token = strtok(NULL,seperator);

  }

  return 0;
}

dan
  • 51
  • 3
  • 1
    That's not how `strtok` works. Separators are only 1 character. The input string of separators is treated as an "any of" set. – Gene Nov 25 '19 at 03:46
  • use strstr instead of strtok – rifkin Nov 25 '19 at 03:48
  • 1
    Does this answer your question? [split char string with multi-character delimiter in C](https://stackoverflow.com/questions/29788983/split-char-string-with-multi-character-delimiter-in-c) – kaylum Nov 25 '19 at 03:49

0 Answers0