I need help with the following program I wrote. Im getting a segmentation fault and the warning "assignment makes integer from pointer without cast". Can anyone spot any errors with the program?
#include <stdio.h>
#include <string.h>
#define MAXLENGTH 256
//function portotype
char * next_word(char *instring, char **new_start);
int main ()
{
char instring[MAXLENGTH];
int words;
//char *parsed=;
printf("Enter text of line");
while (1)
{
fgets(instring, MAXLENGTH, stdin);
if (instring[0] == '\n')
break;
//puts(instring);
//need help with what to do here
words=next_word(instring, '\0' );
return 0;
}
}
char *next_word(char *instring, char **new_start)
{
char *token;
if(instring == NULL)
instring=*new_start;
//printf("Adress of instring: %x\n", instring);
//printf("Addres of newstart: %x\n", *new_start);
instring += strspn(instring, '\0');
//printf("Address of instring after strspn: %x\n", instring);
if (*instring == '\0');
return NULL;
token = instring;
instring = strpbrk(token, '\0');
//printf("Address of instring after strpbrk: %x\n", instring);
if (instring = NULL)
{
*new_start = strchr(token, '\0');
}
else
{
*instring = '\0';
*new_start= instring +1;
}
return token;
}