blaze_wk
asked on
Linked list error
typedef struct node {
int num;
struct node *next;
}message;
int main ()
{
FILE *file;
char array[5];
message *temp *head, *ptr, *previous;
head = 0;
if ((file=fopen(argv[1],"r"))
printf("nofile\n");
while (fgets(array, sizeof(array),file)!= NULL)
{
temp = malloc (sizeof(struct node));
temp -> num = atoi(array);
previous = 0;
while ((ptr != 0) && ( (atoi(array)) > (ptr -> num)))
{
previous = ptr;
ptr = ptr -> next;
}
temp -> next = ptr;
if (previous != 0 )
previous -> next = temp;
else
head = temp;
/*im not so sure of how to not add the same value. For example, if num = a previous node,
it wouldn't append that num to the list. */
}
return 0;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hm, im kind of a beginner here.. my atempt at it might not be enough..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry i would need an example to assist me
ASKER
sorry for my lack in C knowledge...
ASKER
brilliant!
it works!
thanks for the help guys
it works!
thanks for the help guys
int FindValue(int value);
So, before trying to insert node into linked list, call function first.