General discussion
September 28, 2009 at 03:00 PM
mkichar

Darn Segmentation fault :(

by mkichar . Updated 16 years, 11 months ago

Hello everyone, I’m very new to C and have a assignment due today that I keep getting the Segmentation fault on. The purpose of the function is to act like strtok using only pointers (no arrays). Pointers are kicking my behind so please keep as ‘dumb’ as you can for me 🙂 I hope someone can help and I appreciate it…

#include
#include

char *stok(char *str, char ch)
{
static char *nexttok;
nexttok = str;
char *temp;
char *insight;

if (str != NULL) {
while(*nexttok != ch && *nexttok != ‘\0’)
{
nexttok++;
}
if(*nexttok == ‘\0’)
{
return NULL;
}
temp = nexttok;

temp = ‘\0’;
return nexttok++;
printf(“%d”, *nexttok);
}
else {
insight = nexttok;
while((*insight != ch) && (*insight != ‘\0’))
{
printf(“In the first while loop”);
insight++;
}
if (*insight == ‘\0’)
{
return NULL;
}
temp = nexttok;
while(*temp == ch)
{
printf(“Value of temp %d”, *temp);
temp++;
}
temp = ‘\0’;
return nexttok;
}
}

This discussion is locked

All Comments