Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to a singly linked structured list.

Status
Not open for further replies.

LucemFerre

Programmer
Oct 20, 2004
1
AU
I have been searching everywhere for information about how to do this, without much luck.
I establish my structure as:

struct commands
{
int xcoord;
int ycoord;
char instructions[30];
struct commands *next;
};

And there are two ways I can go. One is prompt for input three times which will be stored in three seperate variables, with which I'd like to pass to the structure and store them in the required fields.

The other is to prompt for one long string, then store the first value in the xcoord field, the second value in the ycoord field and the final values in the instructions field.

Which will be the best to use, and how would I go about writing the data to the structure as that's the part that has me stumped.

Thanks for the help.
 
How about 3 functions with these properties

Code:
// allocates a node, and initialises default values
struct commands *allocate_node ( void );

// passed a pointer to a previously allocated node
// prompts user for information
// returns node if successful or NULL on error
struct commands *complete_details ( struct commands *node );

// appends node to the given list
// the return result is the head of the new list
struct commands *append_list ( struct commands *head, struct commands *node );

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top