N
Neil
Hello all!
I wrote program with a array of pointers, and I suspect they are
pointing at each other in the Do ...While loop.
Something is messed up with the increment variable word. A program
clip of what I'm talking about.
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[50] = {"Have a nice day folks"};
char *line_ptr;
char *list[20] = { '\0' }; //Initialize the array of pointers to
NULL.
int word = 0;
line_ptr = strtok(string, " ");
do
{
list[word] = line_ptr;
word++;
line_ptr = strtok(NULL," ");
} while (line_ptr != NULL);
return 0;
}
It's kinda weird, cause the program repeats itself when I run it. I
left out the output section, cause I know it works fine. In the
debugger it works OK. Is there a memory leak? Do you need to assign
pointers to NULL after you use them? Should I free up the memory from
the array of pointers before the program terminates? What is the best
way handle pointers after your done with them?
Thanks for all your help
Neil
I wrote program with a array of pointers, and I suspect they are
pointing at each other in the Do ...While loop.
Something is messed up with the increment variable word. A program
clip of what I'm talking about.
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[50] = {"Have a nice day folks"};
char *line_ptr;
char *list[20] = { '\0' }; //Initialize the array of pointers to
NULL.
int word = 0;
line_ptr = strtok(string, " ");
do
{
list[word] = line_ptr;
word++;
line_ptr = strtok(NULL," ");
} while (line_ptr != NULL);
return 0;
}
It's kinda weird, cause the program repeats itself when I run it. I
left out the output section, cause I know it works fine. In the
debugger it works OK. Is there a memory leak? Do you need to assign
pointers to NULL after you use them? Should I free up the memory from
the array of pointers before the program terminates? What is the best
way handle pointers after your done with them?
Thanks for all your help
Neil