I have a linked list whose elements are of type
typedef struct List * News;
struct List
{
char * Text;
News NextN;
};
In the main function I declared an array of type News as follows
News PTH[50];
for (i = 0; i < 50; i++)
{
PTH[i] = (News) malloc(sizeof(struct List));
PTH[i] -> Text = NULL;
PTH[i] -> NextN = NULL;
}
I added new nodes in the beginning of the list with
if ( PTH[i] -> Text == NULL)
PTH[i] -> Text = msg;
else
{
t -> Text = msg;
t -> NextN = PTH[i];
PTH[i] = t;
}
Where msg is a array of char of length 2000; and and then tried to print the texts apointed by PTH[i] -> Text with
p = PTH[i];
if (p -> Text != NULL)
{
printf("%s", p -> Text);
p = p -> NextN;
}
while (p != NULL)
{
printf("%s", p -> Text);
p = p -> NextN;
}
}
This algorithm only add one node. The error is how I define the PTH or is there an error in how I put nodes in the list.
Newsis before theListstructure definition, right? Because as written, this won't compile. Further,sizeof(struct News)? There is nostruct News, so that won't compile regardless. Kindly post the real code in compilable form.