سؤال

hey i am trying to use the strtok function in C with " " as a delimiter and for some reason it does not work. can some one please tell me how to parse using strtok with a space as a delimiter thanks in advance

هل كانت مفيدة؟

المحلول

Stolen (and slightly modified) from here.

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str," ");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, " ");
  }
  return 0;
}

نصائح أخرى

Use tab "\t" or use both " \t" ie. space and tab both...see if it works

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top