dev-cpp-users Mailing List for Dev-C++ (Page 371)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
| 2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
| 2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
| 2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
| 2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
| 2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
| 2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
| 2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
| 2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
| 2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
| 2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
| 2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
| 2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
| 2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
| 2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
| 2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: CARLSON, J. M. <CA...@st...> - 2003-06-08 20:59:04
|
I am sure this has got to be simple, but I have yet to find any documetation.... How can you print to the printer instead of the screen in C++ Thanks for any help, Jay |
|
From: Luigi S. <gi...@li...> - 2003-06-08 20:29:24
|
On Sat, Jun 07, 2003 at 09:38:34PM +0200, Per Westermark wrote:
> [...]
>
> I know it's a bit extra noisy with dual indirection, but since the code
> is C and not C++, slstore() can't take references to pointers.
>
> /Per W
Probably, he could have avoided the double indirection using
something like:
struct slist
{
struct address *start;
struct address *last;
};
so that a pointer to "struct slist" would be used, still allowing
all changes to "start" and "last" to be made.
--
>> gisan >>
|
|
From: Per W. <pw...@ia...> - 2003-06-08 19:08:12
|
The code below should work ok for a copy constructor. My note about
assigning to a non-empty tree is based on the assumption that you would
like to use copyTree() to implement an assignment operator too, an then
the target BST might already contain a tree.
/Per W
On Sun, 8 Jun 2003, Socha, David F wrote:
> Would a copy constructor as such work:
>
>
> template <typename T> BST<T>::BST(const BST& origTree){ //copy constructor
>
>
> if(origTree.root){
>
> copyTree(origTree.root, root);
>
> }
>
> else{
>
> root = NULL;
>
> }
>
> }
>
>
> also, what do you mean by assigning to a non-empty tree. I would think that the copy constructor would simply make a fresh (new) copy of the tree. I dont understand why you would have to worry about releasing memory for a non empty tree
>
> thanks,
>
> David Socha
>
> here is the copy tree code again
>
>
> > > /****************************************************************************
> > >
> > > copyTree function
> > >
> > > Used by the copy constructor to copy the tree
> > >
> > > Sent: pointer to the original node, pointer to the node being copied to
> > >
> > > Returns: Nothing
> > >
> > > Works by: Creating a new node on the tree being copied, copy the data to the
> > >
> > > node, checks to see if a left node exists on the tree, if yes
> > >
> > > repeat the process using on the left node, if not, do nothing. Then checks
> > >
> > > the right, if it exists repeat process on the right side, if not, do nothing
> > >
> > > NOTE: This function is a recursive process
> > >
> > > ****************************************************************************/
> > >
> > >
> > >
> > > template<typename T> void BST<T>::copyTree(Node* origNode, Node* copyNode){
> > >
> > > copyNode = new Node(origNode->data);
> > >
> > >
> > >
> > > if(origNode->left){
> > >
> > > copyTree(origNode->left, copyNode->left);
> > >
> > > }
> > >
> > >
> > >
> > > if(origNode->right){
> > >
> > > copyTree(origNode->right, copyNode->right);
> > >
> > > }
> > >
> > > }
> > >
> > > //End copyTree
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> thread debugger on the planet. Designed with thread debugging features
> you've never dreamed of, try TotalView 6 free at www.etnus.com.
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Giligun <too...@ya...> - 2003-06-08 18:25:00
|
Could someone who remembers send me a reminder of how to unsubscribe? __________________________________ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com |
|
From: <or...@vp...> - 2003-06-08 17:04:50
|
Psymaster ??????? wrote: > Could you please help me? I have tried dev-c++ packages and it always > gives an error about "winmain@16" or "SDL_init" something. I think I'm > doing everything right, I've added the compiler command-line options, > and sdl.dll in /system32 but no go. Do you link with libSDL.a (or something similar) and the windows subsystem (-mwindows)? -- Greetings, Balázs |
|
From: Socha, D. F <dav...@us...> - 2003-06-08 16:54:44
|
Would a copy constructor as such work:
=20
template <typename T> BST<T>::BST(const BST& origTree){ //copy =
constructor
=09
if(origTree.root){
copyTree(origTree.root, root);
}
else{
root =3D NULL;
}
}
also, what do you mean by assigning to a non-empty tree. I would think =
that the copy constructor would simply make a fresh (new) copy of the =
tree. I dont understand why you would have to worry about releasing =
memory for a non empty tree
thanks,
David Socha
here is the copy tree code again
> > =
/************************************************************************=
****
> >
> > copyTree function
> >
> > Used by the copy constructor to copy the tree
> >
> > Sent: pointer to the original node, pointer to the node being copied =
to
> >
> > Returns: Nothing
> >
> > Works by: Creating a new node on the tree being copied, copy the =
data to the
> >
> > node, checks to see if a left node exists on the tree, if yes
> >
> > repeat the process using on the left node, if not, do nothing. Then =
checks
> >
> > the right, if it exists repeat process on the right side, if not, do =
nothing
> >
> > NOTE: This function is a recursive process
> >
> > =
*************************************************************************=
***/
> >
> >
> >
> > template<typename T> void BST<T>::copyTree(Node* origNode, Node* =
copyNode){
> >
> > copyNode =3D new Node(origNode->data);
> >
> >
> >
> > if(origNode->left){
> >
> > copyTree(origNode->left, copyNode->left);
> >
> > }
> >
> >
> >
> > if(origNode->right){
> >
> > copyTree(origNode->right, copyNode->right);
> >
> > }
> >
> > }
> >
> > //End copyTree
|
|
From: Per W. <pw...@ia...> - 2003-06-08 16:04:02
|
Slight clarification.
Your copy constructor doesn't have to be prepared to release any old
memory - but should be prepared to assign NULL values.
However, if you want to use copyTree() to implement an assignment
operator, then you must also think about releasing an old tree.
/Per W
On Sun, 8 Jun 2003, Per Westermark wrote:
> Your copy constructor - and your copyTree() method - would not work.
>
> What if you make assign to a non-empty tree. In that case, you have to
> release the old tree before assigning the new.
>
> Also, you only handle the case where origTree does contain anything. If it
> doesn't, then the target tree should have the same pointer set to NULL.
>
> /Per W
>
> On Sun, 8 Jun 2003, Socha, David F wrote:
>
> > I am using the most current version of DEV C++
> >
> > This is the code I am currently using for copy constructor on my Binary Search Tree code. I don't believe this should cause any problems but if anyone can give me help on this I would greatly appricate it. Keep in mind that the copy Tree function works on a recursive basis
> >
> >
> >
> > template <typename T> BST<T>::BST(const BST& origTree){ //copy constructor
> >
> > if(origTree.root){
> >
> > copyTree(origTree.root, root);
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > /****************************************************************************
> >
> > copyTree function
> >
> > Used by the copy constructor to copy the tree
> >
> > Sent: pointer to the original node, pointer to the node being copied to
> >
> > Returns: Nothing
> >
> > Works by: Creating a new node on the tree being copied, copy the data to the
> >
> > node, checks to see if a left node exists on the tree, if yes
> >
> > repeat the process using on the left node, if not, do nothing. Then checks
> >
> > the right, if it exists repeat process on the right side, if not, do nothing
> >
> > NOTE: This function is a recursive process
> >
> > ****************************************************************************/
> >
> >
> >
> > template<typename T> void BST<T>::copyTree(Node* origNode, Node* copyNode){
> >
> > copyNode = new Node(origNode->data);
> >
> >
> >
> > if(origNode->left){
> >
> > copyTree(origNode->left, copyNode->left);
> >
> > }
> >
> >
> >
> > if(origNode->right){
> >
> > copyTree(origNode->right, copyNode->right);
> >
> > }
> >
> > }
> >
> > //End copyTree
> >
> > Thanks for all the help,
> >
> > David Socha
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> > thread debugger on the planet. Designed with thread debugging features
> > you've never dreamed of, try TotalView 6 free at www.etnus.com.
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> thread debugger on the planet. Designed with thread debugging features
> you've never dreamed of, try TotalView 6 free at www.etnus.com.
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-06-08 15:50:50
|
Your copy constructor - and your copyTree() method - would not work.
What if you make assign to a non-empty tree. In that case, you have to
release the old tree before assigning the new.
Also, you only handle the case where origTree does contain anything. If it
doesn't, then the target tree should have the same pointer set to NULL.
/Per W
On Sun, 8 Jun 2003, Socha, David F wrote:
> I am using the most current version of DEV C++
>
> This is the code I am currently using for copy constructor on my Binary Search Tree code. I don't believe this should cause any problems but if anyone can give me help on this I would greatly appricate it. Keep in mind that the copy Tree function works on a recursive basis
>
>
>
> template <typename T> BST<T>::BST(const BST& origTree){ //copy constructor
>
> if(origTree.root){
>
> copyTree(origTree.root, root);
>
> }
>
> }
>
>
>
>
>
> /****************************************************************************
>
> copyTree function
>
> Used by the copy constructor to copy the tree
>
> Sent: pointer to the original node, pointer to the node being copied to
>
> Returns: Nothing
>
> Works by: Creating a new node on the tree being copied, copy the data to the
>
> node, checks to see if a left node exists on the tree, if yes
>
> repeat the process using on the left node, if not, do nothing. Then checks
>
> the right, if it exists repeat process on the right side, if not, do nothing
>
> NOTE: This function is a recursive process
>
> ****************************************************************************/
>
>
>
> template<typename T> void BST<T>::copyTree(Node* origNode, Node* copyNode){
>
> copyNode = new Node(origNode->data);
>
>
>
> if(origNode->left){
>
> copyTree(origNode->left, copyNode->left);
>
> }
>
>
>
> if(origNode->right){
>
> copyTree(origNode->right, copyNode->right);
>
> }
>
> }
>
> //End copyTree
>
> Thanks for all the help,
>
> David Socha
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> thread debugger on the planet. Designed with thread debugging features
> you've never dreamed of, try TotalView 6 free at www.etnus.com.
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Per W. <pw...@ia...> - 2003-06-08 15:40:15
|
If the list is non-empty, then *last is non-NULL. In that case, the OLD last entry should have it's next pointer pointing at the NEW last entry. It doesn't matter if the list was empty or not. After an insert - the insert is always at the end of the list - *last should be set to point to the NEW last entry. Without this last line, LAST would always be NULL, and you wouldn't get a linked list. /Per W On Sun, 8 Jun 2003, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Saturday, June 07, 2003 10:39 PM > > To: Ioannis Vranos > > Cc: 'Dev-Cpp-Users' > > Subject: RE: [Dev-C++] Single Linked List-IV > > > > > > The slstore() function DOES need it's last line, or else the > > list will not > > get a pointer to the last element. The pointer to the last > > element is used > > to allow insert of new elements last, without having to > > iterate throught > > the list. > > > Perhaps I am missing something but as I understand it the statement > > *last_arg=i; > > makes the preceding statement > > else > (*last_arg)->next=i; > > > redundant. > > > > > > > I know it's a bit extra noisy with dual indirection, but > > since the code > > is C and not C++, slstore() can't take references to pointers. > > > And? double pointers occupy space themselves too. > > > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL 1: http://run.to/noicys > * Alternative URL 2: http://www.noicys.cjb.net > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Etnus, makers of TotalView, The best > thread debugger on the planet. Designed with thread debugging features > you've never dreamed of, try TotalView 6 free at www.etnus.com. > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Psymaster ??????? <ro...@ho...> - 2003-06-08 14:49:41
|
Could you please help me? I have tried dev-c++ packages and it always gives an error about "winmain@16" or "SDL_init" something. I think I'm doing everything right, I've added the compiler command-line options, and sdl.dll in /system32 but no go. _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus |
|
From: Socha, D. F <dav...@us...> - 2003-06-08 14:30:42
|
I am using the most current version of DEV C++
=20
This is the code I am currently using for copy constructor on my Binary =
Search Tree code. I don't believe this should cause any problems but if =
anyone can give me help on this I would greatly appricate it. Keep in =
mind that the copy Tree function works on a recursive basis
=20
template <typename T> BST<T>::BST(const BST& origTree){ //copy =
constructor
if(origTree.root){
copyTree(origTree.root, root);
}
}
=20
=20
/************************************************************************=
****
copyTree function
Used by the copy constructor to copy the tree
Sent: pointer to the original node, pointer to the node being copied to
Returns: Nothing
Works by: Creating a new node on the tree being copied, copy the data to =
the
node, checks to see if a left node exists on the tree, if yes
repeat the process using on the left node, if not, do nothing. Then =
checks
the right, if it exists repeat process on the right side, if not, do =
nothing
NOTE: This function is a recursive process
*************************************************************************=
***/
=20
template<typename T> void BST<T>::copyTree(Node* origNode, Node* =
copyNode){
copyNode =3D new Node(origNode->data);
=20
if(origNode->left){
copyTree(origNode->left, copyNode->left);
}
=20
if(origNode->right){
copyTree(origNode->right, copyNode->right);
}
}
//End copyTree
Thanks for all the help,
David Socha
|
|
From: Ioannis V. <iv...@em...> - 2003-06-08 12:47:53
|
-----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Socha, David F > Sent: Sunday, June 08, 2003 2:06 PM > To: Dev C++ Mailing List > Subject: [Dev-C++] Pointers and copy constructors > Please define language, C or C++. > item 1: Are pointers passed by value or by reference In C by value, in C++ can be passed in both ways (by reference using templates). > item 2: Would it be a problem if in my copy constructor I > called a function to recursivly move through a binary search > tree and copy the data, keep in mind my BST is made of a > series of linked, dynamically alocated pointers. If it is an external function no, provided that you will not run out of memory. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Ioannis V. <iv...@em...> - 2003-06-08 12:39:33
|
> -----Original Message-----
> From: Per Westermark [mailto:pw...@ia...]
> Sent: Saturday, June 07, 2003 10:39 PM
> To: Ioannis Vranos
> Cc: 'Dev-Cpp-Users'
> Subject: RE: [Dev-C++] Single Linked List-IV
>
>
> The slstore() function DOES need it's last line, or else the
> list will not
> get a pointer to the last element. The pointer to the last
> element is used
> to allow insert of new elements last, without having to
> iterate throught
> the list.
Perhaps I am missing something but as I understand it the statement
*last_arg=i;
makes the preceding statement
else
(*last_arg)->next=i;
redundant.
>
> I know it's a bit extra noisy with dual indirection, but
> since the code
> is C and not C++, slstore() can't take references to pointers.
And? double pointers occupy space themselves too.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|
|
From: Socha, D. F <dav...@us...> - 2003-06-08 11:14:44
|
item 1: Are pointers passed by value or by reference =20 item 2: Would it be a problem if in my copy constructor I called a = function to recursivly move through a binary search tree and copy the = data, keep in mind my BST is made of a series of linked, dynamically = alocated pointers. =20 Thanks for all the help David Socha |
|
From: Christian S. <sm...@xs...> - 2003-06-08 04:21:10
|
Hi, So I just found out that I can use GCC/MingGW to do closed source applications: << http://www.fsf.org/licenses/gpl-faq.html#CanIUseGPLToolsForNF >> But can I use the c lib (stdio,string, time and others) for closed source applications?? Or should I download and use the MS C lib? I would like to stay with DevCPP and use wxwindows + stl + clib and develop someday closed source applications next to open source. |
|
From: Ioannis V. <iv...@em...> - 2003-06-07 23:32:13
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Socha, David F > Sent: Saturday, June 07, 2003 2:35 PM > To: Dev C++ Mailing List > Subject: [Dev-C++] Constructors for classes >=20 > node* root =3D new node(5); >=20 > that should alocate the memory, call the constructor, and set=20 > the data portion of the node to 5. > the constructor that is called is the one that will assign a=20 > value to data not the default constructor that does nothing, right? No, it is not the default constructor. There are two types of "default constructors". The default constuctor = and the default copy constructor. If you define them, the defined ones get called. There is no other type of "default constructor" so if you had = not defined the one getting the int, you would get an error. The other default thing is the default assign operator (that is =3D). = Both the default copy constructor and the default assign operator copy the exact = data member values. When defined, the defined ones get called. Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Ioannis V. <iv...@em...> - 2003-06-07 23:32:08
|
I have sent a few emails to Colin Laplace 1-2 weeks ago and I have not received any answer. Has anyone communicated with Colin lately? Regards, Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Per W. <pw...@ia...> - 2003-06-07 19:43:00
|
The slstore() function DOES need it's last line, or else the list will not
get a pointer to the last element. The pointer to the last element is used
to allow insert of new elements last, without having to iterate throught
the list.
I know it's a bit extra noisy with dual indirection, but since the code
is C and not C++, slstore() can't take references to pointers.
/Per W
On Sat, 7 Jun 2003, Ioannis Vranos wrote:
> > -----Original Message-----
> > From: dev...@li...
> > [mailto:dev...@li...] On Behalf
> > Of Andr? Macario Barros
> > Sent: Friday, June 06, 2003 3:16 PM
> > To: Dev-Cpp-Users
> > Subject: [Dev-C++] Single Linked List-IV
> >
> >
> > Dear users,
> > Please consider this (modificated) Single Linked List Code:
> >
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> >
> > #define MAX 5
> >
> > struct address
> > {
> > char name[40];
> > char phone[20];
> > struct address *next;
> > };
> >
> > void slstore(struct address *, struct address **, struct address **);
> > void display(struct address *);
> > void list(struct address **);
> > void init(struct address **);
> >
> > int main()
> > {
> > struct address *info=3DNULL, *start=3DNULL, *last=3DNULL;
> > int i;
> >
> > for(i=3D0; i<MAX; i++)
> > {
> > init(&info);
> > printf("Enter name: ");
> > gets(info->name);
>
>
> Dangerous, you can't expect the user to know the internals of your code a=
nd
> limit himself to 39 characters. Use fgets() instead. Avoid gets() in
> general.
>
> fgets(info->name, 40, stdin);
>
>
> > printf("Entre com phone: ");
> > gets(info->phone);
>
>
> fgets(info->phone, 20, stdin);
>
>
> > slstore(info, &start, &last);
> > }
> > printf("List Recorded:\n");
> > list(&start);
> > while (start)
> > {
> > info =3D start;
> > start =3D start->next;
> > free(info);
> > }
> > system("PAUSE");
> > return(0);
> > }
> >
> > void slstore(struct address *i, struct address **start_arg,
> > struct address **last_arg)
> > {
> > if(*last_arg=3D=3DNULL)
> *start_arg=3Di;
> > else
> (*last_arg)->next=3Di;
>
> > i->next=3DNULL;
> > *last_arg=3Di;
> > }
>
>
> I made the above more readable so as to understand it. Why do you use str=
uct
> **s and not struct *s and avoid those *s?
>
> I cannot understand the last line, it seems to contradict with the else
> statement at least. I suspect a bug here. Ommiting the last line it becom=
es:
>
> void slstore(struct address *i, struct address *start_arg,
> struct address *last_arg)
> {
> if(last_arg=3D=3DNULL)
> start_arg=3Di;
>
> else
> last_arg->next=3Di;
>
> i->next=3DNULL;
> }
>
>
>
> >
> > void display(struct address *info)
> > {
> > printf("Actual address-->%p\n", info);
>
> When you pass a different pointer than expected in a variadic function yo=
u
> must cast:
>
> printf("Actual address-->%p\n", (void *)info);
>
>
>
>
> > printf("%s\n", info->name);
> > printf("%s\n", info->phone);
> > printf("Next address-->%p\n", info->next);
>
>
> printf("Next address-->%p\n", (void *) info->next);
>
>
> > printf("\n");
> > system("PAUSE");
> > }
> >
> > void list(struct address **start_arg)
> > {
> > struct address *info;
> >
> > init(&info);
> > info =3D *start_arg;
> > while(info)
> > {
> > display(info);
> > info =3D info->next;
> > }
> > }
>
>
> You use **s while they are not needed in the whole program.
>
>
>
>
> > void init(struct address **arg)
> > {
> > *arg=3D malloc(1*sizeof(struct address));
> > if(!(*arg))
> > {
> > printf("sem mem=F3ria\n");
> > system("PAUSE");
> > exit(EXIT_FAILURE);
> > }
> > }
>
>
> The same here. Without **s:
>
>
> void init(struct address *arg)
> {
> arg=3D malloc(sizeof(*arg));
>
> if(!arg)
> {
> printf("He was a good man, always to remember him\n");
> system("PAUSE");
> exit(EXIT_FAILURE);
> }
> }
>
>
> > =3D=3D>My questions:
> > A) One example of addresses that are printed on the screen are:
> > 002224C8
> > 00222510
> > 00222558
> > 002225A0
> > 002225E8
> > The distance between theese addresses is 72 bytes, not 64
> > as expected
> > because the size of the struct address.
> > WHY?
>
>
>
> If I recall correctly you create them on the free store, so their address
> can be anywhere.
>
>
>
>
>
> >
> > B) Could the final loop:
> > while (start)
> > {
> > info =3D start;
> > start =3D start->next;
> > free(info);
> > }
> > be changed by a function call for a function like
> >
> > free_ptr(&start);
> >
> > void free_ptr(struct address **arg)
> > {
> > struct address *info=3DNULL;
> >
> > while (*arg)
> > {
> > info =3D *arg;
> > *arg =3D (*arg)->next;
> > free(info);
> > }
> > }
>
>
> Yes, isn't it exactly the same with the unneeded use of **s? Better:
>
>
> void free_ptr(struct address *arg)
> {
> struct address *info;
>
> while (arg)
> {
> info =3D arg;
> arg =3D arg->next;
> free(info);
> }
> }
>
>
>
>
>
>
> Ioannis Vranos
>
> * Programming pages: http://www.noicys.freeurl.com
> * Alternative URL 1: http://run.to/noicys
> * Alternative URL 2: http://www.noicys.cjb.net
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The best
> thread debugger on the planet. Designed with thread debugging features
> you've never dreamed of, try TotalView 6 free at www.etnus.com.
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: todd b. <tb...@nw...> - 2003-06-07 16:38:33
|
Hiya, I wanted to use the ncurses lib inorder to get the clrscr() = functionality like in conio. I am not sure what I should be downloading = (I see a lot of linux talk) or how to install, or even if I already have = it with dev-c 4.9.8. I appreciate anything to point me in the right = direction!=20 Thanks |
|
From: <or...@vp...> - 2003-06-07 12:39:04
|
Socha, David F wrote: > if i use this code later on in a program and create a new node dynamically using code such as: > > node* root = new node(5); > > that should alocate the memory, call the constructor, and set the data portion of the node to 5. > > the constructor that is called is the one that will assign a value to data not the default constructor that does nothing, right? Of course. If the compiler does not complain, then it found a matching overloaded function (constructor). It would give an error, if it cannot find a matching function. Try node *root = new node(5,5); to see, what error would you get. Anyway, why don't you use built-in C++ storage? It already has vectors, lists, etc. -- Greetings, Balázs |
|
From: Socha, D. F <dav...@us...> - 2003-06-07 11:39:48
|
If I had a node class (such as would be used in a linked list or a =
binary search tree) as such:
=20
class node{
public:
=20
int data; //contains the data stored in the node
=20
node* next; //pointer to the next node
=20
node(){ //default constructor
}
=20
node(int insData){ //constructor that accepts parameters
data =3D insData;
}
=20
~node(){ //destructor
}
};
=20
if i use this code later on in a program and create a new node =
dynamically using code such as:
node* root =3D new node(5);
that should alocate the memory, call the constructor, and set the data =
portion of the node to 5.
=20
the constructor that is called is the one that will assign a value to =
data not the default constructor that does nothing, right?
=20
Thanks for all of your help,
David Socha
|
|
From: Ioannis V. <iv...@em...> - 2003-06-07 10:58:53
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Andr? Macario Barros
> Sent: Friday, June 06, 2003 3:16 PM
> To: Dev-Cpp-Users
> Subject: [Dev-C++] Single Linked List-IV
>=20
>=20
> Dear users,
> Please consider this (modificated) Single Linked List Code:
>=20
>=20
> #include <stdio.h>
> #include <stdlib.h>
>=20
> #define MAX 5
>=20
> struct address
> {
> char name[40];
> char phone[20];
> struct address *next;
> };
>=20
> void slstore(struct address *, struct address **, struct address **);
> void display(struct address *);
> void list(struct address **);
> void init(struct address **);
>=20
> int main()
> {
> struct address *info=3DNULL, *start=3DNULL, *last=3DNULL;
> int i;
>=20
> for(i=3D0; i<MAX; i++)
> {
> init(&info);
> printf("Enter name: ");
> gets(info->name);
Dangerous, you can't expect the user to know the internals of your code =
and
limit himself to 39 characters. Use fgets() instead. Avoid gets() in
general.
fgets(info->name, 40, stdin);
> printf("Entre com phone: ");
> gets(info->phone);
fgets(info->phone, 20, stdin);
> slstore(info, &start, &last);
> }
> printf("List Recorded:\n");
> list(&start);
> while (start)
> {
> info =3D start;
> start =3D start->next;
> free(info);
> }
> system("PAUSE");
> return(0);
> }
>=20
> void slstore(struct address *i, struct address **start_arg,
> struct address **last_arg)
> {
> if(*last_arg=3D=3DNULL)
*start_arg=3Di;
> else
(*last_arg)->next=3Di;
> i->next=3DNULL;
> *last_arg=3Di;
> }
I made the above more readable so as to understand it. Why do you use =
struct
**s and not struct *s and avoid those *s?
I cannot understand the last line, it seems to contradict with the else
statement at least. I suspect a bug here. Ommiting the last line it =
becomes:
void slstore(struct address *i, struct address *start_arg,
struct address *last_arg)
{
if(last_arg=3D=3DNULL)=20
start_arg=3Di;
=20
else
last_arg->next=3Di;
=20
i->next=3DNULL;
}
>=20
> void display(struct address *info)
> {
> printf("Actual address-->%p\n", info);
When you pass a different pointer than expected in a variadic function =
you
must cast:
printf("Actual address-->%p\n", (void *)info);
> printf("%s\n", info->name);
> printf("%s\n", info->phone);
> printf("Next address-->%p\n", info->next);
printf("Next address-->%p\n", (void *) info->next);
> printf("\n");
> system("PAUSE");
> }
>=20
> void list(struct address **start_arg)
> {
> struct address *info;
>=20
> init(&info);
> info =3D *start_arg;
> while(info)
> {
> display(info);
> info =3D info->next;
> }
> }
You use **s while they are not needed in the whole program.
> void init(struct address **arg)
> {
> *arg=3D malloc(1*sizeof(struct address));
> if(!(*arg))
> {
> printf("sem mem=F3ria\n");
> system("PAUSE");
> exit(EXIT_FAILURE);
> }
> }
The same here. Without **s:
void init(struct address *arg)
{
arg=3D malloc(sizeof(*arg));
if(!arg)
{
printf("He was a good man, always to remember him\n");
system("PAUSE");
exit(EXIT_FAILURE);
}
}
> =3D=3D>My questions:
> A) One example of addresses that are printed on the screen are:
> 002224C8
> 00222510
> 00222558
> 002225A0
> 002225E8
> The distance between theese addresses is 72 bytes, not 64=20
> as expected
> because the size of the struct address.
> WHY?
If I recall correctly you create them on the free store, so their =
address
can be anywhere.
>=20
> B) Could the final loop:
> while (start)
> {
> info =3D start;
> start =3D start->next;
> free(info);
> }
> be changed by a function call for a function like
>=20
> free_ptr(&start);
>=20
> void free_ptr(struct address **arg)
> {
> struct address *info=3DNULL;
>=20
> while (*arg)
> {
> info =3D *arg;
> *arg =3D (*arg)->next;
> free(info);
> }
> }
Yes, isn't it exactly the same with the unneeded use of **s? Better:
void free_ptr(struct address *arg)
{
struct address *info;
=20
while (arg)
{
info =3D arg;
arg =3D arg->next;
free(info);
}
}
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|
|
From: Muhammad F. <mf...@ww...> - 2003-06-07 09:04:42
|
Hi, I am using Dev-Cpp 4.9.8.0 with GCC 3.2. I am trying to compile Hello World program of WxWindows (template included in dev-cpp) but it is giving me a lot of errors. 15--C:\Dev-Cpp\include\wx\wx.h-----In file included from C:/Dev-Cpp/include/wx/wx.h 5--C:\Dev-Cpp\MyStuff\wintest\main.cpp----from main.cpp 320--C:\Dev-Cpp\include\wx\defs.h----redeclaration of C++ built-in type `bool' 17--C:\Dev-Cpp\include\wx\debug.h----In file included from C:/Dev-Cpp/include/wx/debug.h 468--C:\Dev-Cpp\include\wx\defs.h----from C:/Dev-Cpp/include/wx/defs.h 15--C:\Dev-Cpp\include\wx\wx.h----from C:/Dev-Cpp/include/wx/wx.h 5--C:\Dev-Cpp\MyStuff\wintest\main.cpp----from main.cpp 6--C:\Dev-Cpp\include\wx\wxchar.h:429--#error "Please define string case-insensitive compare for your OS/compiler" ..... and a lot of same looking errors. Please guide me how to overcome these errors. Regards, Farhan -- Open WebMail Project (http://openwebmail.org) |
|
From: Luigi S. <gi...@li...> - 2003-06-07 04:24:18
|
On Thu, Jun 05, 2003 at 09:31:41PM -0400, JB Maust wrote: > Hello, > > I am trying to compile a modular program. Is there an order to this (i.e. if I'm using Borland C++ Compiler at the DOS command prompt I'd have to compile each file separately, but with Dev C++ 4 (an IDE) I'm not sure. > > When I try to compile the files separately, I get zero errors but zero bytes compiled ... what could be wrong? > > [...] > > -- > J.B. Hi J.B. With Dev-C++, to produce the binary file of an application whose source code spans more than one file, create a "Project" and add all the source files to it. At that point, you just have to build the project to have the binary produced. -- >> gisan >> |
|
From: Luigi S. <gi...@li...> - 2003-06-07 04:24:12
|
Hi Andre',
IMHO, code below should be changed such that:
- use of function "gets" is avoided (because it does not check
if overflow occurs)
- memory used for the nodes of the list should be deallocated
- initialization of pointers START and LAST, before placing
any element on the list, does not require them pointing to some
allocated memory
- if portable code is of interest, use of OS specific functions
(such as Dos "PAUSE") should be avoided
Item #1 is a warning that Gcc issues (if you enable warnings)
Item #2 is the reason of your mail, I'll say something about it later
Item #3 is a small detail you probably overlooked, see comments in code below
Item #4 reflects my personal tastes
Now back to your original question. Generally, a container (like a list)
has functions that push elements (as the slstore you provide) as well as
function that pop elements. Also there might be the need for a clean-up
function, which would remove all items on the list when you no longer
need the container (and haven't popped out all elements yet). In this case,
you are concerned with cleaning up operations, a possible inteface to such
a function, could be:
void
clean_up(struct address **start, struct address **last);
A simple implementation could be:
- while there is something on the list (that is, *START is not 0)
- duplicate value of *START using a temporary pointer
- update *START (so that it points to second element, which
eventually may be 0, when there is only one element left on the list)
- free memory pointed by the temporary pointer
- update *LAST, setting it to 0, thus leaving the list in a
consistent state
I hope the above was of some help.
--
>> gisan >>
On Thu, Jun 05, 2003 at 10:58:18PM -0300, Andr? Mac?rio Barros wrote:
> Dear Users,
>
> I need to discover a way to use the "free" command to correctly avoid 5
> records dinamically allocated in a simple Single Linked List program.
> Here are some pieces of it:
>
> [...]
>
> int main()
> {
>
> struct address *info, *start, *last;
>
> init(&start); /* here start is assigned some memory */
> start=NULL; /* throwing away the address, so can't free it anymore */
> init(&last); /* allocating memory for last */
> last=NULL; /* throwing away the address */
/* above 4 lines could be folded into one line,
also avoiding the memory leaks related to them:
start = last = 0;
*/
> for(i=0; i<MAX; i++)
> {
> init(&info);
> printf("Enter name: ");
> gets(info->name); /* should be avoided */
> printf("Enter phone: ");
> gets(info->phone); /* should be avoided */
> slstore(info, &start, &last);
> }
> ...
> system("PAUSE"); /* this makes your code non portable, also
it is not needed, if you run console
application from a console window */
> return(0);
> }
>
> [...]
|