hi.. i am posting this thread because i hoping that somebody can help me about my problem. this freakn me out. i checked the code well and i got this 1 irritating error that i can't fixed out.
my code is this
newPtr = malloc(sizeof(ListNode));
where ListNode is my alias of my strcut definition i had declare earlier.
what is the problem that my compiler says "cannot convert void * to listnode *".. what is the problem with my code?
The problem is that this code is not valid C++. It is valid C, though, perhaps you meant to use a C compiler?
Equivalent C++ would be newPtr = new ListNode;
(or you could force your original line to compile with newPtr = static_cast<ListNode*>(malloc(sizeof(ListNode))); or equivalent explicit cast, but, depending on the contents of ListNode, it may or may not fail at runtime)
@cire:
I didn't know about that.
But yet his problem is related to using C code for C++.
Also, I'm sure you can cast pointers in C, and that isn't of any trouble.
is it not possible to compile turbo c code in a c++ compiler?
You could give the file an extension of .c rather than .cpp.
But bear in mind that the Turbo C compiler, though good in its time, allowed (or forced) the use of some non-standard code. It also had the occasional bug, which might have forced the use of idiosyncratic code to work around the defect.
If you have old code of your own, then I'd recommend you update it to modern standards.
printf("Enter a character:");
scanf("\n%c", &item);
insert(&startPtr, item);
printList(startPtr);
break;
case2:
if (!isEmpty(startPtr))
{
printf("Enter character to be deleted:");
scanf("\n%c", &item);
if(delet(&startPtr, item ))
{
printf("%c deleted.\n",item);
printList(startPtr);
}
else
printf("%c not found.\n\n item");
}
else
printf("List is empty.\n\n");
break;
default:
printf("Invalid choice.\n\n");
instructions();
break;
}
printf("?");
scanf("&d", &choice);
}
printf("End of run.\n");
return 0;
}
void instructions(void)
{
printf("Enter your choice.\n");
printf("1 to insert an element into the list.n");
printf("2 to insert an element into the list.\n");
printf("3 to end.\n");
}
void insert( ListNodePtr *sPtr, char value)
{
ListNodePtr newPtr;
ListNodePtr previousPtr;
ListNodePtr currentPtr;