|
-
November 12th, 2007, 03:30 PM
#1
Senior Member
First, I am sorry for my later reply, but I was out of town for a while 
nebulus200, I didn't get you ... I have two structures - temp and list. list i poiting to the start of the list and temp - to the end. Do you mean something like this:
Code:
struct *ctrl, *node;
node=list;
ctrl=node;
ctrl->next=temp
-
November 13th, 2007, 05:44 PM
#2
Senior Member
I googled for this problem and changed the functions in this way:
Code:
void Print(currency *list)
{
if (list!=NULL)
while(list)
{
printf("%d\t%s\t%s\t%.4f\n", list->number, list->name, list->code, list->number);
list=list->next;
}
else
printf("Spisakat e prazen.\n");
}
Code:
void InsertItem(currency *list)
{
currency temp, tmp;
fflush(stdin);
printf("Vavedi valuta: ");
scanf("%s", &temp.name);
printf("Vavedi kod na valutata: ");
scanf("%s", &temp.code);
printf("Vavedi stoinost za 1USD: ");
scanf("%f", &temp.value);
temp.number=++cnt;
temp.next=NULL;
list=&temp;
}
But now it gives me exception on this (in print() function):
Code:
printf("%d\t%s\t%s\t%.4f\n", list->number, list->name, list->code, list->number);
-
November 14th, 2007, 06:22 AM
#3
when you use currency *list, you are actually using a pointer to a pointer or in other words a double pointer so that you can actually modify the pointer's location and move it around the list instead of doing a return everytime to the single pointer.
Now coming to the display function, I see no need to use a double pointer as you are not modifying the list pointer.
I will be pasting a code here
Code:
void display(currency list)
{
currency temp=list;
while(temp!=NULL)
{
cout<<temp->info<<"\t"; //put your structure members here
temp=temp->next;
}
}
the problem with your code was that you were using a double pointer and instead of storing the pointer to list in a temp variable, you were doing
Code:
if (list!=NULL)
while(list)
{
printf("%d\t%s\t%s\t%.4f\n", list->number, list->name, list->code, list->number);
list=list->next;
Since you were using a pointer to the pointer list, the above function should use something like (*list)->number and *list=(*list)->next. But even this is not recommended, as it takes list for a nice trip through the linked list and it would end up at the very last element of the list. So after displaying if you run another function like insertion, it may end up inserting at the rear instead of at the front.
Hope this makes things clear
Last edited by pi><boy; November 14th, 2007 at 06:27 AM.
-
November 14th, 2007, 07:31 AM
#4
Senior Member
But now it gives me error "binary '=' : no operator defined which takes a right-hand operand of type 'struct curr *' (or there is no acceptable conversion)" on
I tried in this way:
bu it gives me exception on this row at runtime.
-
November 14th, 2007, 08:41 AM
#5
oops, I have made a mistake here. Extremely sorry for that. I didn't notice that the typedef was only for the structure, not for a pointer to the structure.
So everything I wrote in my previous post wont help in this context. Just doing the following SHOULD solve it.
Code:
void display(currency *list)
{
currency *temp=list;
while(temp!=NULL)
{
cout<<temp->number<<temp->name<<"\n";
temp=temp->next;
}
}
Again extremely sorry for the confusion I created.
Last edited by pi><boy; November 14th, 2007 at 08:46 AM.
Similar Threads
-
By IcSilk in forum Operating Systems
Replies: 8
Last Post: October 30th, 2005, 11:01 PM
-
By XTC46 in forum Site Feedback/Questions/Suggestions
Replies: 15
Last Post: August 24th, 2005, 07:52 PM
-
By journy101 in forum Programming Security
Replies: 3
Last Post: August 13th, 2003, 05:31 PM
-
By pctwister in forum Hardware
Replies: 4
Last Post: July 24th, 2003, 08:27 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|