• ベストアンサー

strtok関数 自作

strtok関数の内部の処理がしりたいので、自作された事がある方はぜひソースプログラムを教えてください。

質問者が選んだベストアンサー

  • ベストアンサー
  • BLK314
  • ベストアンサー率55% (84/152)
回答No.2

1: /* 2: * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. 3: * See the copyright notice in the ACK home directory, in the file "Copyright". 4: */ 5: /* $Header: strspn.c,v 1.1 89/05/11 10:09:09 eck Exp $ */ 6: 7: #include <string.h> 8: 9: size_t 10: strspn(const char *string, const char *in) 11: { 12: register const char *s1, *s2; 13: 14: for (s1 = string; *s1; s1++) { 15: for (s2 = in; *s2 && *s2 != *s1; s2++) 16: /* EMPTY */ ; 17: if (*s2 == '\0') 18: break; 19: } 20: return s1 - string; 21: }

その他の回答 (2)

  • BLK314
  • ベストアンサー率55% (84/152)
回答No.3

1: /* 2: * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. 3: * See the copyright notice in the ACK home directory, in the file "Copyright". 4: */ 5: /* $Header: strpbrk.c,v 1.2 89/12/18 16:02:21 eck Exp $ */ 6: 7: #include <string.h> 8: 9: char * 10: strpbrk(register const char *string, register const char *brk) 11: { 12: register const char *s1; 13: 14: while (*string) { 15: for (s1 = brk; *s1 && *s1 != *string; s1++) 16: /* EMPTY */ ; 17: if (*s1) 18: return (char *)string; 19: string++; 20: } 21: return (char *)NULL; 22: }

  • BLK314
  • ベストアンサー率55% (84/152)
回答No.1

/* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* $Header: strtok.c,v 1.2 90/08/28 13:54:38 eck Exp $ */ #include <string.h> char * strtok(register char *string, const char *separators) { register char *s1, *s2; static char *savestring; if (string == NULL) { string = savestring; if (string == NULL) return (char *)NULL; } s1 = string + strspn(string, separators); if (*s1 == '\0') { savestring = NULL; return (char *)NULL; } s2 = strpbrk(s1, separators); if (s2 != NULL) *s2++ = '\0'; savestring = s2; return s1; }

it200189
質問者

お礼

ありがとうございました!!

関連するQ&A