Hey everyone,

I'm having this serious problem with this linke dlist implementation. It is susposed to be part of a flight reservtion system (basic introductory problem in C) - but everytime the execution of initiateNode begins, the program crashes, saying that "The instruction at xxxxxx referenced memory at xxxxxxx. The memory could not be written"

I understand that this is a problem with reserved memory trying to be used, but I don't known how to fix it -

Heres the parts of the code that are most likely the culprits!

-------------------Code------------------------------

//-------------------------- initiateNode --------------------------//

/* This function initialises a node, allocates memory for the node,
and returns a pointer to the new node. Name, Phone and Flight number
are added at this stage. Uses add function to establish node
on the actual linked list.*/

struct node * initiateNode(char *name, char *flight_no, int phone)
{
struct node *ptr;
ptr = (struct node *) malloc( 1, sizeof(struct node ) );
//In case of an error, ptr set to NULL, so...
if(ptr == NULL)
return (struct node *) NULL;
//Otherwise take passenger details and.
else
{
strcpy(ptr->name, name);
ptr->phone = phone;
strcpy(ptr->flight_no, flight_no);
return ptr;
//This is pointer to the new node.
}
}


//-------------------------- add --------------------------//

/* This adds a node to the end of the list (doesn't fill in detials).*/
void add(struct node *newNode)
{
if( head == NULL )
{
//If this is the first node...
head = newNode;
}
(*end).next = newNode;
(*newNode).next = NULL;
// Set next field to signify the end of list
end = newNode;
// Make end to point to the last node
}


This is the implementation part - not all of it!


case 2:
printf("\nEnter name: ");
scanf("%s", &name);
printf("\nEnter phone number: ");
scanf("%d", &phone);
printf("\nCurrent Flights Available: ");
for(i = 0; i < number; i++)
{
printf("%s\n", current_flight[i].flight_no);
}//Ignore this part
printf("\nEnter Flight number for passenger: ");
scanf("%s", &flight_no);
ptr = initiateNode(name, flight_no, phone);
add(ptr);
break;

There is also two global variables

struct node *head = NULL;
struct node *end = NULL;


_________________end code_________________

I know its probably too much to ask, but does anyone have any ideas???