473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

edit list

Hi,

I am writing for some help with editing a linked list.
I would be gratful if anybody has the time to take a look at this.

I am trying to edit a node by entering a date as a key.
If an existing date is entered then you can edit the specified node.

I have the date defined as a nested structure and it is in three parts
(ie: yyyy, mm, dd ) and referenced by the main structure.
My problem is how do I refer to the full date in the edit function to
check if the date entered is a valid date (ie: already stored in the
list) ?

I have tried this but with no luck.
Has anyone got any idea where i'm going wrong?

Also, is my edit function correct?
Any help would be much aprechiated.

Thanks in advance,
Ritchie

------------ code -------------
struct orderDate {
int year;
int month;
int day;
};
typedef struct orderDate OrderDate;

struct node {
OrderDate order_date;
int name
Nov 14 '05 #1
7 1709
ritchie wrote:
I am trying to edit a [LL] node by entering a date as a key.
If an existing date is entered then you can edit the specified node.

I have the date defined as a nested structure and it is in three parts
(ie: yyyy, mm, dd ) and referenced by the main structure.
My problem is how do I refer to the full date in the edit function to
check if the date entered is a valid date (ie: already stored in the
list) ?
[snip] ------------ code -------------
struct orderDate {
int year;
int month;
int day;
};
typedef struct orderDate OrderDate; struct node {
OrderDate order_date;
int name
.
.
struct node *next;
};
typedef Node *nPtr;
Firstly, it is generally considered bad practice to typedef pointer
types. Also, your syntax is incorrect here. ITYM

typedef struct node Node;

Then, you can use Node* when referring to pointers to Nodes.

Secondly, you need a function which either compares Nodes by OrderDate,
or a function which simply compares OrderDates. Given two objects a and
b, such a function will typically return 0 if a==b, < 0 (e.g., -1) if
a < b, and > 0 (e.g., 1) if a > b; the function indicates how a compares
to b.
/***iEdit is the node (date entered) to be edited***/
void editList( NodePtr *sPtr, int iEdit )
void editList( Node *sPtr, int iEdit)

Your description of iEdit is confusing. I think you want iEdit to have
type OrderDate. Thus, you will edit the node matching the given date
(iEdit) if your list (sPtr) contains such a node.
{
NodePtr currPtr, prevPtr = NULL;

if( *sPtr == NULL ) {
printf( "List empty\n" );
}
else
if( iEdit == (*sPtr)->order_date ) //PROBLEM HERE
{
printf("Enter new value: "); scanf("%d", &(*sPtr)->name);
...


You want something more like

int
editList(Node *l, OrderDate date)
{
Node *np;

for(np=l; np != 0; np=np->next){
if(datecmp(date, np->order_date) == 0){
printf("Enter new value: ");
fflush(stdout); /* this is important! */
scanf("%d", np->name); /* use correct pointer! */
/* ... */
return 1;
}
}
return 0; /* node not found */
}

BTW, the part where you read values can (and probably should) be
formulated as a separate function.

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Nov 14 '05 #2
Hi,

Thanks for the reply, but I am still having trouble accessing the full date.
My date is in three parts in a nested structure - ie:yyyymmdd.

For example if I even try:
/************************************************** *********/
while( curPtr != NULL && dateIn > curPtr->order_date )
{
prevPtr = curPtr;
curPtr = curPtr->nextPtr;
}
/************************************************** *********/

I get an error saying " '>' illegal for struct"...
Or even if I try to printf the date ie:
/* printf("%d", currPtr->order_date); */

but it's ok if I
/* printf("%d%d", currPtr->order_date.year, currPtr->order_date.month ); */

Is it possible to access the full date (yyyymmdd).

Can anyone see why this would cause an error?
I really would aprechiate any help on this.

Thanks again,
Ritchie


David Rubin <no****@nowhere.net> wrote in message news:<c0********@netnews.proxy.lucent.com>...
ritchie wrote:
I am trying to edit a [LL] node by entering a date as a key.
If an existing date is entered then you can edit the specified node.

I have the date defined as a nested structure and it is in three parts
(ie: yyyy, mm, dd ) and referenced by the main structure.
My problem is how do I refer to the full date in the edit function to
check if the date entered is a valid date (ie: already stored in the
list) ?


[snip]
------------ code -------------
struct orderDate {
int year;
int month;
int day;
};
typedef struct orderDate OrderDate;

struct node {
OrderDate order_date;
int name
.
.
struct node *next;
};
typedef Node *nPtr;


Firstly, it is generally considered bad practice to typedef pointer
types. Also, your syntax is incorrect here. ITYM

typedef struct node Node;

Then, you can use Node* when referring to pointers to Nodes.

Secondly, you need a function which either compares Nodes by OrderDate,
or a function which simply compares OrderDates. Given two objects a and
b, such a function will typically return 0 if a==b, < 0 (e.g., -1) if
a < b, and > 0 (e.g., 1) if a > b; the function indicates how a compares
to b.
/***iEdit is the node (date entered) to be edited***/
void editList( NodePtr *sPtr, int iEdit )


void editList( Node *sPtr, int iEdit)

Your description of iEdit is confusing. I think you want iEdit to have
type OrderDate. Thus, you will edit the node matching the given date
(iEdit) if your list (sPtr) contains such a node.
{
NodePtr currPtr, prevPtr = NULL;

if( *sPtr == NULL ) {
printf( "List empty\n" );
}
else
if( iEdit == (*sPtr)->order_date ) //PROBLEM HERE
{
printf("Enter new value: "); scanf("%d", &(*sPtr)->name);
...


You want something more like

int
editList(Node *l, OrderDate date)
{
Node *np;

for(np=l; np != 0; np=np->next){
if(datecmp(date, np->order_date) == 0){
printf("Enter new value: ");
fflush(stdout); /* this is important! */
scanf("%d", np->name); /* use correct pointer! */
/* ... */
return 1;
}
}
return 0; /* node not found */
}

BTW, the part where you read values can (and probably should) be
formulated as a separate function.

/david

Nov 14 '05 #3


ritchie wrote:
Hi,

Thanks for the reply, but I am still having trouble accessing the full date.
My date is in three parts in a nested structure - ie:yyyymmdd.

For example if I even try:
/************************************************** *********/
while( curPtr != NULL && dateIn > curPtr->order_date )
{
prevPtr = curPtr;
curPtr = curPtr->nextPtr;
}
/************************************************** *********/

I get an error saying " '>' illegal for struct"...
Or even if I try to printf the date ie:
/* printf("%d", currPtr->order_date); */

but it's ok if I
/* printf("%d%d", currPtr->order_date.year, currPtr->order_date.month ); */

Is it possible to access the full date (yyyymmdd).

Can anyone see why this would cause an error?
I really would aprechiate any help on this.

Thanks again,
Ritchie


You specifically declared stuct orderDate to contain
three element. You must the three elements
explicity.

On the other hand, you could try a union
which would allow you to access the same
information in an alternative way.


David Rubin <no****@nowhere.net> wrote in message news:<c0********@netnews.proxy.lucent.com>...
ritchie wrote:

I am trying to edit a [LL] node by entering a date as a key.
If an existing date is entered then you can edit the specified node.

I have the date defined as a nested structure and it is in three parts
(ie: yyyy, mm, dd ) and referenced by the main structure.
My problem is how do I refer to the full date in the edit function to
check if the date entered is a valid date (ie: already stored in the
list) ?


[snip]
------------ code -------------
struct orderDate {
int year;
int month;
int day;
};
typedef struct orderDate OrderDate;



struct node {
OrderDate order_date;
int name
.
.
struct node *next;
};
typedef Node *nPtr;


Firstly, it is generally considered bad practice to typedef pointer
types. Also, your syntax is incorrect here. ITYM

typedef struct node Node;

Then, you can use Node* when referring to pointers to Nodes.

Secondly, you need a function which either compares Nodes by OrderDate,
or a function which simply compares OrderDates. Given two objects a and
b, such a function will typically return 0 if a==b, < 0 (e.g., -1) if
a < b, and > 0 (e.g., 1) if a > b; the function indicates how a compares
to b.

/***iEdit is the node (date entered) to be edited***/
void editList( NodePtr *sPtr, int iEdit )


void editList( Node *sPtr, int iEdit)

Your description of iEdit is confusing. I think you want iEdit to have
type OrderDate. Thus, you will edit the node matching the given date
(iEdit) if your list (sPtr) contains such a node.

{
NodePtr currPtr, prevPtr = NULL;

if( *sPtr == NULL ) {
printf( "List empty\n" );
}
else
if( iEdit == (*sPtr)->order_date ) //PROBLEM HERE
{
printf("Enter new value: "); scanf("%d", &(*sPtr)->name);
...


You want something more like

int
editList(Node *l, OrderDate date)
{
Node *np;

for(np=l; np != 0; np=np->next){
if(datecmp(date, np->order_date) == 0){
printf("Enter new value: ");
fflush(stdout); /* this is important! */
scanf("%d", np->name); /* use correct pointer! */
/* ... */
return 1;
}
}
return 0; /* node not found */
}

BTW, the part where you read values can (and probably should) be
formulated as a separate function.

/david


--
Ñ
"It is impossible to make anything foolproof because fools are so
ingenious" - A. Bloch

Nov 14 '05 #4
ritchie wrote:

Thanks for the reply, but I am still having trouble accessing the
full date. My date is in three parts in a nested structure -
ie:yyyymmdd.

For example if I even try:
/************************************************** *********/
while( curPtr != NULL && dateIn > curPtr->order_date )
{
prevPtr = curPtr;
curPtr = curPtr->nextPtr;
}
/************************************************** *********/

I get an error saying " '>' illegal for struct"...
Or even if I try to printf the date ie:
/* printf("%d", currPtr->order_date); */

but it's ok if I
/* printf("%d%d", currPtr->order_date.year, currPtr->order_date.month ); */

Is it possible to access the full date (yyyymmdd).

Can anyone see why this would cause an error?
I really would aprechiate any help on this.


Due to top-posting (don't do that, your answer goes below the
material to which you reply, with non-germane parts snipped) there
is no definition of such things as curPtr, dateIn, nextPtr, etc.
However, the error message seems self-explanatory to me.

Next time, define everything used, and DO NOT top-post in this
newsgroup.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #5
ritchie <ri*********@yahoo.com> spoke thus:
My date is in three parts in a nested structure - ie:yyyymmdd. while( curPtr != NULL && dateIn > curPtr->order_date ) I get an error saying " '>' illegal for struct"...
/* printf("%d", currPtr->order_date); */
Why does this surprise you? order_date IS a struct, not an integer or
anything else that you can meaningfully compare to an integer.
but it's ok if I
/* printf("%d%d", currPtr->order_date.year, currPtr->order_date.month ); */ Is it possible to access the full date (yyyymmdd).


Not without resorting to undesireable tricks without much prospects
for treats. What you're trying to do just isn't possible, for a
number of reasons. You can't access elements (other than the first)
of a struct without explicitly doing so, period. The FAQ has some
interesting suggestions concerning structs that you may find useful.
Even if this worked, of course, you do realize that you wouldn't get
yyyymmdd if the month and/or day were less than 10.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #6
ritchie wrote:

[snip - top posting corrected]
------------ code -------------
struct orderDate {
int year;
int month;
int day;
};
typedef struct orderDate OrderDate;

[snip]Secondly, you need a function which either compares Nodes by OrderDate,
or a function which simply compares OrderDates. Given two objects a and
b, such a function will typically return 0 if a==b, < 0 (e.g., -1) if
a < b, and > 0 (e.g., 1) if a > b; the function indicates how a compares
to b.

[snip] Thanks for the reply, but I am still having trouble accessing the full date.
My date is in three parts in a nested structure - ie:yyyymmdd.

For example if I even try:
/************************************************** *********/
while( curPtr != NULL && dateIn > curPtr->order_date )
{
prevPtr = curPtr;
curPtr = curPtr->nextPtr;
}
/************************************************** *********/

I get an error saying " '>' illegal for struct"...
Or even if I try to printf the date ie:
/* printf("%d", currPtr->order_date); */


What you want is something like this:

/* return -1, 0, 1 depending on whether d1 is before, same, or after d2 */
int
datecmp(const OrderDate *d1, const OrderDate *d2)
{
if(d1->year < d2->year) return -1;
if(d1->year > d2->year) return 1;

if(d1->month < d2->month) return -1;
if(d1->month > d2->month) return 1;

if(d1->day < d2->day) return -1;
if(d1->day > d2->day) return 1;

/* dates are the same */
return 0;
}

I think you need to review structures and how to access fields...

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Nov 14 '05 #7
Hi,

Just wanted to thanks everyone for their replies and comments.

Thanks again,
Ritchie

David Rubin <no****@nowhere.net> wrote in message news:<c1********@netnews.proxy.lucent.com>...
ritchie wrote:

[snip - top posting corrected]
------------ code -------------
struct orderDate {
int year;
int month;
int day;
};
typedef struct orderDate OrderDate;
[snip]Secondly, you need a function which either compares Nodes by OrderDate,
or a function which simply compares OrderDates. Given two objects a and
b, such a function will typically return 0 if a==b, < 0 (e.g., -1) if
a < b, and > 0 (e.g., 1) if a > b; the function indicates how a compares
to b.


[snip]
> Thanks for the reply, but I am still having trouble accessing the full date.
> My date is in three parts in a nested structure - ie:yyyymmdd.
>
> For example if I even try:
> /************************************************** *********/
> while( curPtr != NULL && dateIn > curPtr->order_date )
> {
> prevPtr = curPtr;
> curPtr = curPtr->nextPtr;
> }
> /************************************************** *********/
>
> I get an error saying " '>' illegal for struct"...
> Or even if I try to printf the date ie:
> /* printf("%d", currPtr->order_date); */


What you want is something like this:

/* return -1, 0, 1 depending on whether d1 is before, same, or after d2 */
int
datecmp(const OrderDate *d1, const OrderDate *d2)
{
if(d1->year < d2->year) return -1;
if(d1->year > d2->year) return 1;

if(d1->month < d2->month) return -1;
if(d1->month > d2->month) return 1;

if(d1->day < d2->day) return -1;
if(d1->day > d2->day) return 1;

/* dates are the same */
return 0;
}

I think you need to review structures and how to access fields...

/david

Nov 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
0
by: San Diego Guy | last post by:
Hi all! I have Datagrid. Within that datagrid I have a drop down list that I set up some values in (a "collection") I set up an edit command column on the datagrid and wrote simple code to get...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
0
by: Adam Knight | last post by:
Hi all, I have two nested DataLists. When I click edit in the parent list the edit comand executes and the required Edit Item Template is displayed. The child list is display in the...
2
by: P. Yanzick | last post by:
Hello, I am creating an edit template for a FormView control, changing one of the textboxes to a dropdown box. The dropdown will be populated from a simple table with the primary key, and a...
9
bhcob1
by: bhcob1 | last post by:
Hey guys, 'Update or CancelUpdate without AddNew or Edit' On my database i keep occasionly get this error when i try and edit a field, it is not everytime. It will be working fine and then this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.