I am trying to pass a pointer to a linked list to a function. I want the function to modify the linked list.
In the function, If I print out sp->sv_id, I get a good value, but in main if I print out pointer->sv_id, I get junk.
Since pointer is a pointer, shouldn't it get modified by the function?
Thanks for the help
Carl
#include <stdio.h>
#include <string.h>
struct ActiveServices{
int sv_id;
struct ActiveServices *next;
};
int myfunct (struct ActiveServices *sp);
int main ()
{
int index;
struct ActiveServices *pointer;
myfunct(pointer);
printf ("IN MAIN IT IS %d\n", pointer->sv_id);
return (0);
}
int myfunct (struct ActiveServices *sp)
{
int count;
struct ActiveServices *p;
sp = (struct ActiveServices *)malloc(sizeof(struct ActiveServices));
sp->next = 0;
p=sp;
for (count=0;count<=13;count++)
{
p->sv_id=count;
p->next = (struct ActiveServices *)malloc(sizeof(struct ActiveServices));
p = p->next;
}
p=sp;
return (0);
}
In the function, If I print out sp->sv_id, I get a good value, but in main if I print out pointer->sv_id, I get junk.
Since pointer is a pointer, shouldn't it get modified by the function?
Thanks for the help
Carl
#include <stdio.h>
#include <string.h>
struct ActiveServices{
int sv_id;
struct ActiveServices *next;
};
int myfunct (struct ActiveServices *sp);
int main ()
{
int index;
struct ActiveServices *pointer;
myfunct(pointer);
printf ("IN MAIN IT IS %d\n", pointer->sv_id);
return (0);
}
int myfunct (struct ActiveServices *sp)
{
int count;
struct ActiveServices *p;
sp = (struct ActiveServices *)malloc(sizeof(struct ActiveServices));
sp->next = 0;
p=sp;
for (count=0;count<=13;count++)
{
p->sv_id=count;
p->next = (struct ActiveServices *)malloc(sizeof(struct ActiveServices));
p = p->next;
}
p=sp;
return (0);
}