473,809 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1746
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.yea r, currPtr->order_date.mon th ); */

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.yea r, currPtr->order_date.mon th ); */

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(No de *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.yea r, currPtr->order_date.mon th ); */

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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #5
ritchie <ri*********@ya hoo.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.yea r, currPtr->order_date.mon th ); */ 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)cybers pace.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
10428
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 for people whose ID is in the list box. I made minor changes to the code (mainly replacing rs.AddNew with rs.Edit)and it appears to be updating only the first record and then overwriting that record with the next, etc until it runs out of ID's...
0
1227
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 me in to edit mode: sub dgEdit(ByVal s As Object, ByVal e As DataGridCommandEventArgs) dgStatus.EditItemIndex = e.Item.ItemIndex bindData() 'This is just a sub I wrote to re-bind the data
3
4379
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 be really grateful for any assistance! Thanks
0
1016
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 SELECTED ITEM TEMPLATE for a given parent list item. When I click edit for a child list item, the required function executes, the
2
8746
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 description (i.e. a colors table, so there is a colors ID and a color description). The data source the FormView is pulling data from stores (in this example) the primary key for the colors table. My ultimate goal is when the FormView goes into...
9
7756
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 error appears. I will be editing records and then a random one will get the error. A bit of background on my form, this will seem a bit lengthy but here is my code. The form has a navigation list which the user can select a record to view. An...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10378
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.