W
whiteboy
My assignment is to duplicate the strtok function. My problem is i get
"access violation" errors when I try to turn a single char in a char*,
as I should. My question is how do I get around this? I know you can
change individual chars in a char array, but don't know how to
implement it. This code is a work in progress and is by no means
complete. Here's my code so far.
#include <iostream>
using namespace std;
char *bk_strtoke(char *, const char *);
int main()
{
char *tokethis = "Hello, EE*L&,3^*801";
char *stoned = bk_strtoke(tokethis, "&*^");
system("PAUSE");
return 0;
}
char *bk_strtoke(char *s1, const char *s2)
{
char *next_token = NULL;
if (*s1 != NULL) static char where_to_start[] = s1;
for (; where_to_start == next_token; where_to_start++)
{
for (int i = 0; i < strlen(s2); i++)
if (*where_to_start != *(s2 + i) && i == 2)
{
next_token = where_to_start;
break;
}
}
for (;; where_to_start++)
{
for (int i = 0; i < strlen(s2); i++)
//access violation error on next line
if (*where_to_start == *(s2 + i)) *where_to_start = '\0';
}
}
"access violation" errors when I try to turn a single char in a char*,
as I should. My question is how do I get around this? I know you can
change individual chars in a char array, but don't know how to
implement it. This code is a work in progress and is by no means
complete. Here's my code so far.
#include <iostream>
using namespace std;
char *bk_strtoke(char *, const char *);
int main()
{
char *tokethis = "Hello, EE*L&,3^*801";
char *stoned = bk_strtoke(tokethis, "&*^");
system("PAUSE");
return 0;
}
char *bk_strtoke(char *s1, const char *s2)
{
char *next_token = NULL;
if (*s1 != NULL) static char where_to_start[] = s1;
for (; where_to_start == next_token; where_to_start++)
{
for (int i = 0; i < strlen(s2); i++)
if (*where_to_start != *(s2 + i) && i == 2)
{
next_token = where_to_start;
break;
}
}
for (;; where_to_start++)
{
for (int i = 0; i < strlen(s2); i++)
//access violation error on next line
if (*where_to_start == *(s2 + i)) *where_to_start = '\0';
}
}