I only had a quick peek at your code, but this jumps out at me from your add function:
If a1 is NULL but a2 is not, you'll attempt to use a1 in the first if and that will segfault as you try to reference memory at 0.
Do you mean while( a1 != NULL && a2 != NULL) by chance?
A side note...
It would also be helpful in future to post the command and arguments you are passing to the programme when it is having issues. If the problem is triggered by data, someone building and testing the code you post might not see the issue.
Problem 1: You malloc a3 initially and fail to initialise ae->link. When you use it in your while, the second time through who knows what a3 is pointing to. Could be a legit address which then will contain corrupted data since you'll over write it, or a bad address which causes your seg-fault when you attempt to update what a3 points at.
Problem 2: You need to alloc more instances of a3 and add them to your list as you go.
Hey everyone, this is my first time posting, so hopefully i won't commit some kind of egregious faux pas. :)
Anyways, I'm trying to create and read back a simple linked list in C++. So far, I think I've built it and filled it with 10 different arrays of characters of about 22 characters each.... (2 Replies)
Hi all,
I have a problem to format data from different database queries into one look. The input data are as follows, every line has the same number of values but a different number of characters:
adata, bdata, cdata, ddata
fffdata, gdata, hdata, idata
jdata, kdata, ... (6 Replies)
I am working on a problem for which I need to use a linked list of a sort. For this particular application I need each node to refer to a set of other nodes.
A simplified version of the code looks as follows:
#include <stdio.h>
#include <stdlib.h>
struct record {
int id;
struct record... (1 Reply)