dev-cpp-users Mailing List for Dev-C++
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
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
|
|
1
(12) |
2
(2) |
3
(16) |
4
(17) |
5
(20) |
|
6
(8) |
7
(26) |
8
(12) |
9
(18) |
10
(33) |
11
(22) |
12
(11) |
|
13
(12) |
14
(30) |
15
(29) |
16
(15) |
17
(18) |
18
(20) |
19
(17) |
|
20
(6) |
21
(34) |
22
(21) |
23
(19) |
24
(22) |
25
(16) |
26
(3) |
|
27
(17) |
28
(8) |
29
(9) |
30
(22) |
31
(17) |
|
|
|
From: David M. <ci...@ya...> - 2003-07-31 17:23:31
|
Application is used to store world data for a game. We wish to use mySQL (or some other SQL database) as well asbe able to store data in flat-files. My biggest problem with flat-files is what would be the best way to store and search such a system of files (a reccomendation, though not a requirement is that the files remain in plain text. The current format is the SMAUG world data format (I can send an example file if you want). Rooms, objects and mobiles are each indexed by an integer value between 0 and 4 billion (2^32 to be exact). A room and a object or mobile can have the same vnum but 2 rooms cannot have the same vnum (same applies to objects and mobiles). In other words the index for rooms / objects / mobiles are separate. Currently the files are sorted and (poorly) indexed. The indexing essentially sets a limit to the contents of a file (i.e. xxx.are contains all rooms/objects/mobiles whose vnums are between x and y, with y-x = 1000) The current system involves loading everything into memory and accessed from there (thus removing the slowdown). Problem is with only ~6000 rooms we are using 12Mb of RAM. Even with virtual memory we are going to start running out of memory as the world gets bigger (for those of you who are about to curse me out for such an inefficient design, please note it is not mine). So far the best solution is to use the room exits. When you enter a room all the rooms connected to it and all the associated objects and mobiles are loaded. That way when the player actually request to go to the next room it is already loaded. Problem is there are 11 possible exits (up, down and in the 8-point cardinal directions as well as through a portal). Unfortunately this means I have a very low chache hit-miss ratio (1:11) is not good odds. Also immortals (as well as some players) have skills that can take them to a random room in the world (there by bypassing my caching system). My question is does anyone know either an algorithm or a library that will allow me to use flat-files fast enough that I don't have to load up everything into memory. I do not require it to handle 4 billion rooms/mobs/objects but be able to handle about 1 million (if they want to go higher they upgrade to mySQL) ===== Signed David Mcken Life Sucks Live with it __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com |
|
From: <ri...@te...> - 2003-07-31 17:04:51
|
Tom Craig wrote:
>It switches the view from the active header file to the C or CPP file of the
>same name, or vice versa - e.g. from xyz.h to xyz.cpp (or xyz.c), or from
>xyz.c/cpp to xyz.h. It's also available if you right-click on your code.
>
>Quite useful, I find.
>
>--Tom
>
>
Well, all is clear now :)
And yes, I think it is useful too. Very thanks.
--
---------------------------------------------------
Ricardo Amores Hernández
ICQ: 19463735
MSN: zheo_ (at) hotmail (dot) es
---------------------------------------------------
|
|
From: David M. <ci...@ya...> - 2003-07-31 16:55:41
|
Thanks for pointing that out..
There is no particular reason for keeping the algorithm.
I just like using less code, this method seems to use more.
(You have the original function and a functor now).
I have another question considering files but I think I
better start another thread for that.
Signed
David Mcken
--- Hossein Haeri <ult...@em...> wrote:
> Hi David,
>
> > Some interesting ideas there. ...
>
> Some? Just some? Oh my Goodness! Thanks for that! I could
> except any
> description expect that one.
>
> > ... You are right I am not too
> > familar with the
> > STL.
>
> You will become! For now on, just don't panic when you
> see powerful
> STL codes.
>
> > ... What is the difference
> > between passing a
> > refrence and passing a const refrence? Is that to
> ensure
> > that the original
> > can never be changed(as would happen of I passed by
> value)?
>
> Hmmm... Yep in the sense that the original beast wouldn't
> be changed,
> but nop in the sense that there is big differnce between
> passing by
> value and passing by reference: The former copies the
> argument at the
> moment of being called, whilst the later doesn't copy,
> it, in turn,
> works on the same object, by creating a reference out of
> the
> argument.
>
> > My other comment is that current_players is a member of
> > pc_char. It is
> > static and thus shared by all instances of pc_char. So
> I am
> > guessing the
> > function signature stays the same.
>
> Well, if you mean the same as what it now is, yes, it
> does. But the
> important point here is that this is the first time I see
> a class
> having a map (in fact, a container) of pointers to
> itself. My
> recommendation is to change this strange design, unless
> you have
> very plausible reasons for adhering to it. It is very
> likely to
> result in sophisticated problems that are all hard to
> debug. (Amongst
> them, one of the most important and vexing ones is the
> "Circular
> Dependancies" problem.)
>
>
> > From the looks of it using for_each may not be worth it
> > especially since the
> > function is not finished.
>
> I read the bellow changes you want to be made. From my
> viewpoint,
> that doesn't difere much the dicision wheather to use or
> not to use
> for_each. Assuming that you are going to do the changes,
> you still can adhere to for_each. Especially because,
> that way, the only
> change is needed to be done is inside that Functor, and
> no where
> else. (Read on ...)
>
> > ...
> > void pc_char::write_to_all_pc(const string& to_send,
> bool
> > add_eoln)
> > {
> > for(map<string, pc_char *>::iterator i =
> > current_players.begin();
> > i != current_players.end(); ++i)
> > if((*i).second != this)
> > (*i).second->write_to_player(to_send, add_eoln);
> > }
>
> At the moment beeing, the only very subtle bug I can see
> in it is the
> one in the following line:
>
> > if((*i).second != this)
>
> Just think about it for a moment. You are storing
> pc_char* objects
> in that map, right? But you are, probabely, just working
> with a copy
> of the addresses of the original objects, huh? So those
> nifty-looking
> pointers, which are beeing stored in the map, and are
> objects by
> themselves, are copies of the "this" objects, and not the
> same ones!
> Hence, althouge they point to the same location in the
> memory, they
> are not the same, by themselves. Therefore, it is very
> likely that
> the test fails, even if the semantic is right. In fact,
> you should be
> very lucky if the code works. The solution I suggest (if
> it is OK
> under your algorithm), is to replace it with the
> following one.
>
> if(*(i->second) != (*this))
>
> This way, you are checking if they are pointing to the
> same location,
> and not if they are the same pointers! (And that's
> presumably what
> you need!)
>
> > With respect to the books. I will look into getting my
> > hands on a copy.
>
> Do it, ASAP.
>
> Regards,
> --Hossein
=====
Signed
David Mcken
Life Sucks
Live with it
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|
|
From: <ten...@ne...> - 2003-07-31 16:54:57
|
Just now I came back to my pad trial to make it recognize UNIX text files and DOS text files, so it displays UNIX files correctly in lines, not one hugh file with black rectangles, an so I substitute notepad with it as the default text file program. It works perfectly . But I found one unconsistency: I wrote two functions, addret and remret, both receive LPTSTR and int&. addret work perfect, I do, in pesudocode: Count \n in the string. Hold the new sizeof the string in variable resize. Allocate space for the extended string. Cycle through the string from beginning to end searching for \n. When I found one I move from there ot end one byte right, from end to the place. Put a \r there. size = resize. Put a '\0' in [resize], although there is yet a '\0'. The result is the desired: I get the UNIX file displayed in lines, with all \n tranfromed in \r\n. The "problem" arises in remret: I count the number of \n (or \r, they're the same). I get the new size in resize. I search for \r, from start to end. When I find it I move all bytes from there to end one byte left. I GlobalRealloc to resize + 1. I make [resize] '\0'. I make size = resize. Now the string is converted to UNIX, where there was a \r\n now there is a \n: but the text has being cut in size - resize characters. Just as if \r\n were only one byte. If I comment the realloc and the [resize] \0, then it works perfect: all the text is converted to UNIX and there is the complete text. Another thing I noticed (I did it as it must, but shouldn't, be done not after seeing that the way it should doesn't work right): GetWindowTextLength retireves the control text length, without the \0 (or even if it includes it). Then GetWindowText retrieves the text of the control until reach the limit set by the third parameter. Nothing is said about the null end character. But consistency demands that if you pass the value retruned by the first function to the second, this will give you the full text (both include or not the end null character). Well, it doesn't: it places a \0 at the last character or doesn't read it, so it cuts the last character, if you really want retrieve the full text you shall add 1 to that value: length = GetWindowTextLength(GetDlgItem(hwnd, ID_EDIT)); text = (LPTSTR)GlobalAlloc(GPTR, length + 1); text[length] = '\0'; GetWindowText(GetDlgItem(hwnd, ID_EDIT), text, length + 1); |
|
From: Tom C. <jat...@nt...> - 2003-07-31 16:27:21
|
"Ricardo Amores Hernández" <ri...@te...> writes: > Does anybody knows what that option (found in edition menu) is used > for? I could not found information about it in the help. It switches the view from the active header file to the C or CPP file of the same name, or vice versa - e.g. from xyz.h to xyz.cpp (or xyz.c), or from xyz.c/cpp to xyz.h. It's also available if you right-click on your code. Quite useful, I find. --Tom |
|
From: David M. <ci...@ya...> - 2003-07-31 16:19:39
|
Cool, thanks for your help
Signed
David Mcken
--- manilius <man...@gm...> wrote:
>
> Hi
>
> > Ok, the idea was to create all the possible
> combinations
> > (up to 100
> > characters long) using all the avalible characters in
> the
> > ascii character
> > set from 32 (space) to 126 (~) inclusive. When we try
> to
> > increment '~' we
> > end up getting a space and we increment the next
> character
> > in the string and
> > applying the same overflow rule.
>
> Okay, that would be one way to do it, but it does involve
> a lot of string
> manipulation (check a character and change it) which is
> not needed with
> recursion. Is there a special reason you want to use your
> "overflow
> algorithm"?
>
> If you want more characters with the recursion example I
> sent you, just add
> them to the character table:
>
> for( int i=0; i<92; i++) CharacterTable.push_back(' '+i);
>
> should include all characters you want.
> If you need zero-terminated strings, you can use the
> function c_str() of the
> std::string class to create them.
>
>
> But again: There is no way to create a list of all
> possible strings with the
> length of 100. You have
>
> (# of possible charcters)^length of the string
>
> possibilities. This results in a huge number (try
> calculate 92^100 :)
>
> ciao...
> ...manilius
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET
> sites including
> Data Reports, E-commerce, Portals, and Forums are
> available now.
> Download today and enter to win an XBOX or Visual Studio
> .NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
=====
Signed
David Mcken
Life Sucks
Live with it
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|
|
From: Hossein H. <ult...@em...> - 2003-07-31 16:12:47
|
Hi David,
> Some interesting ideas there. ...
Some? Just some? Oh my Goodness! Thanks for that! I could except any
description expect that one.
> ... You are right I am not too
> familar with the
> STL.
You will become! For now on, just don't panic when you see powerful
STL codes.
> ... What is the difference
> between passing a
> refrence and passing a const refrence? Is that to ensure
> that the original
> can never be changed(as would happen of I passed by value)?
Hmmm... Yep in the sense that the original beast wouldn't be changed,
but nop in the sense that there is big differnce between passing by
value and passing by reference: The former copies the argument at the
moment of being called, whilst the later doesn't copy, it, in turn,
works on the same object, by creating a reference out of the
argument.
> My other comment is that current_players is a member of
> pc_char. It is
> static and thus shared by all instances of pc_char. So I am
> guessing the
> function signature stays the same.
Well, if you mean the same as what it now is, yes, it does. But the
important point here is that this is the first time I see a class
having a map (in fact, a container) of pointers to itself. My
recommendation is to change this strange design, unless you have
very plausible reasons for adhering to it. It is very likely to
result in sophisticated problems that are all hard to debug. (Amongst
them, one of the most important and vexing ones is the "Circular
Dependancies" problem.)
> From the looks of it using for_each may not be worth it
> especially since the
> function is not finished.
I read the bellow changes you want to be made. From my viewpoint,
that doesn't difere much the dicision wheather to use or not to use
for_each. Assuming that you are going to do the changes, you still can adhere to for_each. Especially because, that way, the only
change is needed to be done is inside that Functor, and no where
else. (Read on ...)
> ...
> void pc_char::write_to_all_pc(const string& to_send, bool
> add_eoln)
> {
> for(map<string, pc_char *>::iterator i =
> current_players.begin();
> i != current_players.end(); ++i)
> if((*i).second != this)
> (*i).second->write_to_player(to_send, add_eoln);
> }
At the moment beeing, the only very subtle bug I can see in it is the
one in the following line:
> if((*i).second != this)
Just think about it for a moment. You are storing pc_char* objects
in that map, right? But you are, probabely, just working with a copy
of the addresses of the original objects, huh? So those nifty-looking
pointers, which are beeing stored in the map, and are objects by
themselves, are copies of the "this" objects, and not the same ones!
Hence, althouge they point to the same location in the memory, they
are not the same, by themselves. Therefore, it is very likely that
the test fails, even if the semantic is right. In fact, you should be
very lucky if the code works. The solution I suggest (if it is OK
under your algorithm), is to replace it with the following one.
if(*(i->second) != (*this))
This way, you are checking if they are pointing to the same location,
and not if they are the same pointers! (And that's presumably what
you need!)
> With respect to the books. I will look into getting my
> hands on a copy.
Do it, ASAP.
Regards,
--Hossein
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
|
|
From: Daniel G. <sp...@ho...> - 2003-07-31 15:49:26
|
did you not say the MS tutorial compiled? does that not connect? >From: "Ed Cottrell" <em...@ed...> >To: <dev...@li...> >Subject: RE: [Dev-C++] OT: Connecting to FoxPro databases with a DSN >Date: Thu, 31 Jul 2003 09:53:58 -0400 > > > Do you get a connection to the database? If so can you perform a simple >SQL > >That's just it - I don't know how to connect to the database from C or C++. >I know the database end of things (SQL, recordsets, all that); I just don't >know how to access the database, at all, with C code. > >-Ed > > > > >From: "Ed Cottrell" <em...@to...> > >To: "'Dev-C++ users'" <dev...@li...> > >Subject: [Dev-C++] OT: Connecting to FoxPro databases with a DSN > >Date: Wed, 30 Jul 2003 16:26:37 -0400 > > > >Hi all - > > > >I know this is not a Dev-C++ post, but I'm a little new to C and am > >desperate for help. I have to convert a Visual Basic program (which I > >wrote) > >to C or C++, the primary purpose of which is to collate information > >from a bunch of databases - currently 12 Foxpro and 1 MySQL - without > >using DSNs. > > > >What I need is for somebody to point me to a resource on how to work > >with the Foxpro ODBC driver from a C/C++ program; the tutorial on > >Microsoft's MSDN site compiled (after some tweaks), but doesn't produce > >any output, and I can't find seem to find the errors. > > > >Many thanks! > > > >-Ed > > > > > >President > >Topsail Consulting, Inc. > >em...@to... > >http://www.topsailconsulting.com > > > >Phone/Fax: 770-719-3332 > >Cell: 404-328-8503 > >155 Shamrock Drive > >Fayetteville, GA 30215-2810 > > > > > > > > > > > >------------------------------------------------------- > >This SF.Net email sponsored by: Free pre-built ASP.NET sites including > >Data Reports, E-commerce, Portals, and Forums are available now. > >Download today and enter to win an XBOX or Visual Studio .NET. > >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_0 > >1/01 > >_______________________________________________ > >Dev-cpp-users mailing list > >Dev...@li... > >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > >_________________________________________________________________ >On the move? Get Hotmail on your mobile phone >http://www.msn.co.uk/msnmobile > > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data >Reports, E-commerce, Portals, and Forums are available now. Download today >and enter to win an XBOX or Visual Studio .NET. >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including >Data Reports, E-commerce, Portals, and Forums are available now. >Download today and enter to win an XBOX or Visual Studio .NET. >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile |
|
From: Ed C. <em...@ed...> - 2003-07-31 13:54:08
|
> Do you get a connection to the database? If so can you perform a = simple SQL=20 That's just it - I don't know how to connect to the database from C or = C++. I know the database end of things (SQL, recordsets, all that); I just = don't know how to access the database, at all, with C code. -Ed=20 >From: "Ed Cottrell" <em...@to...> >To: "'Dev-C++ users'" <dev...@li...> >Subject: [Dev-C++] OT: Connecting to FoxPro databases with a DSN >Date: Wed, 30 Jul 2003 16:26:37 -0400 > >Hi all - > >I know this is not a Dev-C++ post, but I'm a little new to C and am=20 >desperate for help. I have to convert a Visual Basic program (which I >wrote) >to C or C++, the primary purpose of which is to collate information=20 >from a bunch of databases - currently 12 Foxpro and 1 MySQL - without=20 >using DSNs. > >What I need is for somebody to point me to a resource on how to work=20 >with the Foxpro ODBC driver from a C/C++ program; the tutorial on=20 >Microsoft's MSDN site compiled (after some tweaks), but doesn't produce = >any output, and I can't find seem to find the errors. > >Many thanks! > >-Ed > > >President >Topsail Consulting, Inc. >em...@to... >http://www.topsailconsulting.com > >Phone/Fax: 770-719-3332 >Cell: 404-328-8503 >155 Shamrock Drive >Fayetteville, GA 30215-2810 > > > > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including=20 >Data Reports, E-commerce, Portals, and Forums are available now.=20 >Download today and enter to win an XBOX or Visual Studio .NET.=20 >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_0 >1/01 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ On the move? Get Hotmail on your mobile phone = http://www.msn.co.uk/msnmobile ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including = Data Reports, E-commerce, Portals, and Forums are available now. Download = today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/= 01 _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: <ri...@te...> - 2003-07-31 13:53:10
|
Does anybody knows what that option (found in edition menu) is used for?
I could not found information about it in the help.
Thanks in advance, and sorry for my english :(
--
---------------------------------------------------
Ricardo Amores Hernández
ICQ: 19463735
MSN: zheo_ (at) hotmail (dot) es
---------------------------------------------------
|
|
From: Zodiaq <zo...@ac...> - 2003-07-31 10:28:52
|
Hello Neszt and all Dev-C++ users, Thursday, July 31, 2003, 10:52:59 AM, Neszt wrote as follows: NT> Hello! NT> #1: NT> Should I use the sprintf within an opengl application? I'm worrying about NT> the speed. Is sprintf taking a long time? (As I tried it, I can not feel NT> any fall-off) Maybe you could try ostringstream from C++ std namespace?? #include <sstream> static std::ostringstream some_text; //before every next use (after first ) you have to clear it: some_text.str( "" ); //to insert new text use standard stream insertion "<<" some_text << "some text, my fps are: " << fps << " fps"; //to format float and double data types to have only 2 digits after "." //use these: #include <iomanip> some_text << "some text, my fps are: " << std::fixed << std::setprecision( 2 ) << fps << " fps"; //to get standard C's char * string use: some_text.str( ).data( ); C++ STD objects and streams are very fast but remember to use static to only once alocate extra memory needed by ostringstream... if you check it in OpenGL please do tell me result - it is very interesting for me as I never checked this out and I don't really know which one is faster... I know that ostringstream is much more safer as it dynamically allocates needed memory - not like sprintf which writes directly to memory (and here writing beyond buffer is quite often and very dangerous as it leads many times to "random" crashes) Waiting for some results :-) -- regards, Zodiaq |
|
From: Neszt T. <ne...@ss...> - 2003-07-31 08:54:06
|
Hello! #1: Should I use the sprintf within an opengl application? I'm worrying about the speed. Is sprintf taking a long time? (As I tried it, I can not feel any fall-off) #2: Am I know right, that the last stable version of dev-c++ is the 4.0? What about the new stable versions? (I mean, not beta) #3: How to force the dev-c++ to generate .o file to from every .c included file? I think, this could make speed up the compiling process. Thanks Your help in advance, Regards, Neszt Tibor |
|
From: manilius <man...@gm...> - 2003-07-31 08:11:21
|
Hi
=20
> Ok, the idea was to create all the possible combinations
> (up to 100
> characters long) using all the avalible characters in the
> ascii character
> set from 32 (space) to 126 (~) inclusive. When we try to
> increment '~' we
> end up getting a space and we increment the next character
> in the string and
> applying the same overflow rule.
Okay, that would be one way to do it, but it does involve a lot of =
string
manipulation (check a character and change it) which is not needed with
recursion. Is there a special reason you want to use your "overflow
algorithm"?
If you want more characters with the recursion example I sent you, just =
add
them to the character table:
for( int i=3D0; i<92; i++) CharacterTable.push_back(' '+i);
should include all characters you want.
If you need zero-terminated strings, you can use the function c_str() of =
the
std::string class to create them.=20
But again: There is no way to create a list of all possible strings with =
the
length of 100. You have
(# of possible charcters)^length of the string=20
possibilities. This results in a huge number (try calculate 92^100 :)=20
ciao...
...manilius
|
|
From: Daniel G. <sp...@ho...> - 2003-07-31 07:07:10
|
Do you get a connection to the database? If so can you perform a simple SQL query and output to a messagebox to test? >From: "Ed Cottrell" <em...@to...> >To: "'Dev-C++ users'" <dev...@li...> >Subject: [Dev-C++] OT: Connecting to FoxPro databases with a DSN >Date: Wed, 30 Jul 2003 16:26:37 -0400 > >Hi all - > >I know this is not a Dev-C++ post, but I'm a little new to C and am >desperate for help. I have to convert a Visual Basic program (which I >wrote) >to C or C++, the primary purpose of which is to collate information from a >bunch of databases - currently 12 Foxpro and 1 MySQL - without using DSNs. > >What I need is for somebody to point me to a resource on how to work with >the Foxpro ODBC driver from a C/C++ program; the tutorial on Microsoft's >MSDN site compiled (after some tweaks), but doesn't produce any output, and >I can't find seem to find the errors. > >Many thanks! > >-Ed > > >President >Topsail Consulting, Inc. >em...@to... >http://www.topsailconsulting.com > >Phone/Fax: 770-719-3332 >Cell: 404-328-8503 >155 Shamrock Drive >Fayetteville, GA 30215-2810 > > > > > >------------------------------------------------------- >This SF.Net email sponsored by: Free pre-built ASP.NET sites including >Data Reports, E-commerce, Portals, and Forums are available now. >Download today and enter to win an XBOX or Visual Studio .NET. >http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile |
|
From: w.y. <yok...@be...> - 2003-07-31 05:37:56
|
David McKen wrote:
>
> What is this supposed to do?
> (I tried this example program)
>
> #include <stdio.h>
>
> int main()
> {
> int var;
> var = 5;
> printf("%p", &var);
> return 0;
> }
>
> Output:
> 00405020
That's the adress in memory, given in hexadecimal, on your computer
where
the variable called "var" is located at the time you ran your program.
cout << &var;
does the same thing in C++
On my machine printf gives 0022FF6C and cout gives 0x22ff6c.
|
|
From: David M. <ci...@ya...> - 2003-07-31 03:39:50
|
----- Original Message -----
From: "Esteban Valverde" <est...@ho...>
To: "dev-cpp" <dev...@li...>
Sent: Tuesday, July 29, 2003 2:37 PM
Subject: [Dev-C++] Manipulator
> Hi, which is the ostream manipulator to printf the
direction of a varible
?
> In C it can be obtained by the next sentence...
>
> int var;
> ..
> printf("%p", &var);
What is this supposed to do?
(I tried this example program)
#include <stdio.h>
int main()
{
int var;
var = 5;
printf("%p", &var);
return 0;
}
Output:
00405020
>
> bye, Esteban
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com
|
|
From: David M. <ci...@ya...> - 2003-07-31 03:34:30
|
Uh the way I was seeing it was that the recursion would
only go to a level
equal to the length if the string.
Ok, the idea was to create all the possible combinations
(up to 100
characters long) using all the avalible characters in the
ascii character
set from 32 (space) to 126 (~) inclusive. When we try to
increment '~' we
end up getting a space and we increment the next character
in the string and
applying the same overflow rule.
Here are some sections of the expected output:
gksdg
hksdg
iksdg
jksgd
kksgd
.....
|ksgd
}ksgd
~ksgd <-We have reached ~ so the next string will
have <space> and
we have to increment the next character.
lsgd <- Note that this is <space>lsgd
!lsgd
"lsgd
Things get interesting when this situation arises.
y~~~ju
z~~~ju
{~~~ju
|~~~ju
}~~~ju
~~~~ju
<sp><sp><sp><sp>ku <- <sp> = space
in this case we had 4 overflows to deal with
In case you are wondering I am looking for varible length
strings up to the
max (in this case 100).
I hope this makes things clearer. Also '++' works quite
well in incrementing
one character, my problem is with handling the overflow.
Signed
David Mcken
----- Original Message -----
From: "manilius" <man...@gm...>
To: "'Dev-C Mailing List'"
<dev...@li...>
Sent: Wednesday, July 30, 2003 4:54 PM
Subject: AW: [Dev-C++] Producing a endless list of strings.
> Hi,
>
> > Eventually I hope to use this to create strings at
least
> > 100 chars long (possibly 1000). Could someone tell me
if
> > 100 levels using recursion cause a stack overflow?
>
> Do I understand you correctly that you want to create a
list with every
> possible string of 100 or even 1000 characters?
> Even a list of all lower case strings with 10 letters
takes about 10^15
> bytes. You will definitely get a stack overflow :)
>
> But here is how you could do it:
>
> #include <iostream>
> #include <string>
> #include <vector>
> #include <stdlib.h>
>
> using namespace std;
>
> vector<char> CharacterTable;
>
> void CreateAllPossibleStrings(string String, int
RecursionLevel)
> {
> if(RecursionLevel > 0)
> {
> for(int i=0; i<CharacterTable.size(); i++)
>
>
CreateAllPossibleStrings(String+CharacterTable[i],RecursionLevel-1);
> }
> cout << String << endl;
> }
>
> int main(int argc, char *argv[])
> {
> // Init character table, only lower case letters in this
case
> for( int i=0; i<26; i++) CharacterTable.push_back('a'+i);
>
> // Create all strings, recursion depth is 2...try to
increase it :)
> CreateAllPossibleStrings("",2);
>
> system("PAUSE");
> return 0;
> }
>
> ciao...
> ..manilius
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET
sites including
> Data Reports, E-commerce, Portals, and Forums are
available now.
> Download today and enter to win an XBOX or Visual Studio
.NET.
>
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
>
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|
|
From: manilius <man...@gm...> - 2003-07-30 21:07:26
|
Hi,
> Eventually I hope to use this to create strings at least
> 100 chars long (possibly 1000). Could someone tell me if
> 100 levels using recursion cause a stack overflow?
Do I understand you correctly that you want to create a list with every
possible string of 100 or even 1000 characters?
Even a list of all lower case strings with 10 letters takes about 10^15
bytes. You will definitely get a stack overflow :)
But here is how you could do it:
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
vector<char> CharacterTable;
void CreateAllPossibleStrings(string String, int RecursionLevel)
{
if(RecursionLevel > 0)
{
for(int i=0; i<CharacterTable.size(); i++)
CreateAllPossibleStrings(String+CharacterTable[i],RecursionLevel-1);
}
cout << String << endl;
}
int main(int argc, char *argv[])
{
// Init character table, only lower case letters in this case
for( int i=0; i<26; i++) CharacterTable.push_back('a'+i);
// Create all strings, recursion depth is 2...try to increase it :)
CreateAllPossibleStrings("",2);
system("PAUSE");
return 0;
}
ciao...
...manilius
|
|
From: Ed C. <em...@to...> - 2003-07-30 20:26:52
|
Hi all - I know this is not a Dev-C++ post, but I'm a little new to C and am desperate for help. I have to convert a Visual Basic program (which I = wrote) to C or C++, the primary purpose of which is to collate information from = a bunch of databases - currently 12 Foxpro and 1 MySQL - without using = DSNs. What I need is for somebody to point me to a resource on how to work = with the Foxpro ODBC driver from a C/C++ program; the tutorial on Microsoft's MSDN site compiled (after some tweaks), but doesn't produce any output, = and I can't find seem to find the errors. Many thanks! -Ed President Topsail Consulting, Inc. em...@to... http://www.topsailconsulting.com Phone/Fax: 770-719-3332 Cell: 404-328-8503 155 Shamrock Drive Fayetteville, GA 30215-2810 |
|
From: Graham D. <g.d...@nt...> - 2003-07-30 18:47:24
|
char* is more difficult, since there's a specific overload for it that prints a string. I suppose you could cast it to a long and print that. Bit ugly, though. char * str; cout << hex << reinterpret_cast<long>(str) << endl; By the way, my earlier answer could be even simpler: int var; cout << &var << endl; // still prints in hex. Graham Esteban Valverde wrote: >What a dummy !!! thanks... and what about char * ? > >char * str; >... >cout << hex << str > >doesn't works. > > >Esteban > > >----- Original Message ----- >From: "Graham Douglas" <g.d...@nt...> >To: "Esteban Valverde" <est...@ho...> >Sent: Tuesday, 29 July, 2003 16:24 >Subject: Re: [Dev-C++] Manipulator > > >cout << hex << &var << endl; > > > > > |
|
From: Graham D. <g.d...@nt...> - 2003-07-30 17:59:02
|
And now, written in C++ (no mucking about with arrays, pointers or
new/malloc):
#include <iostream> // NB: _not_ iostream.h
#include <string>
#include <vector>
using namespace std;
class str_misc
{
public:
istream& read(istream& is)
{
is >> str;
return is;
}
ostream& write(ostream& os) const
{
os << str;
return os;
}
private:
string str;
};
istream& operator>>(istream& is, str_misc& s)
{
return s.read(is);
}
ostream& operator<<(ostream& os, const str_misc& s)
{
return s.write(os);
}
int main()
{
vector<str_misc> str_ex(12);
cin >> str_ex[0];
cout << str_ex[0] << " Index = 0" << endl;
cin >> str_ex[1];
cout << str_ex[1] << " Index = 1" << endl;
cout << str_ex[0] << " repeat Index = 0" << endl;
cout << str_ex[1] << " repeat Index = 1" << endl;
system("PAUSE");
return 0;
}
dawood wrote:
> Can anybody let me know, why the below code is not working correctly.
>
> #include <iostream.h>
> #include <stdlib.h>
>
> int main()
> {
> struct str_misc {
> char* cstr;
> };
> str_misc str_ex[12];
> char* buf;
>
> cin>>buf;
> str_ex[0].cstr= buf;
> cout<<str_ex[0].cstr<<"index=0"<<'\n';
>
> cin>>buf;
> str_ex[1].cstr= buf;
> cout<<str_ex[1].cstr<<"index=1"<<'\n';
>
> cout<<str_ex[0].cstr<<" repeat index=0"<<'\n';
> cout<<str_ex[1].cstr<<" repeat index=1"<<'\n';
>
> system("PAUSE");
> return 0;
> }
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: <ten...@ne...> - 2003-07-30 17:58:45
|
First, I don't want to be exhaustive, here, but I say what I think right
know.
In a trial I did about filling areas of same color with one I selected
it crashed, in the one I checked the number of recursions performed in
the 57th, the function had seven parameters: two passed by value, two
were pointers and the other three passed by reference.
With a loop it didn't only work fine, but very faster (the loop version
filled a, say as any number, surface of 50 * 50 pixels in one minute and
some seconds, the loop version filled all the screen (800*640) in less
than a second).
I see hard how to do what you want recursively.
I would do a loop like this:
char list[1000][101]; <- I hope these are correctly done: 1000 strings
with 100 chars plus the null
for (int i = 0; i < number_of_strings; i++){
for (int j = 0; j < number_of_chars && list[i][j-1] != '\0'; j++){
list[i][j] = (the number you assign it as you want, as you calculated it
before or here I don't achieve to understand exactly what mean steps 2
and 3.)
if (list[i][j] == 127)
do the transformation you want.
} // second for
}//first for
P.D. - The access violations can be caused by the fact you don't
allocate memory for the pointers you use, if you use them as pointers,
not as statically allocated array, which is what I do inthis piece.
David McKen wrote:
>Ok, this is not a school assignment so please don't ask.
>
>I would like to produce a list of null terminated strings
>that I plan to use to test a hash function. Unfortunately I
>am a bit stumped as what would be the best way to create
>such a list.
>
>The algorithm is as follows:
>1. Start with a string containing only a space.
>
>2. Increment the first character in the string.
>
>3. If the value of the first character is 127 (DEL) then
>set it to 32 (space) and increment the next character
>(repeat this step if that character is 127).
>
>4. print out the string.
>
>5. goto step 2.
>
>I know, Recursion is screaming at me to use it.
>Problem is, how? I am getting stuck in the wind-up section.
>(That and the fact that Visual C++ is giving me access
>violations)
>
>My other question is, does anyone else know another way?
>Eventually I hope to use this to create strings at least
>100 chars long (possibly 1000). Could someone tell me if
>100 levels using recursion cause a stack overflow?
>
>Thanks in Advance
>David Mcken
>
>__________________________________________________
>Do you Yahoo!?
>The New Yahoo! Search - Faster. Easier. Bingo
>http://search.yahoo.com
>
>
>-------------------------------------------------------
>This SF.Net email sponsored by: Free pre-built ASP.NET sites including
>Data Reports, E-commerce, Portals, and Forums are available now.
>Download today and enter to win an XBOX or Visual Studio .NET.
>http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
|
|
From: David M. <ci...@ya...> - 2003-07-30 16:44:30
|
Ok, this is not a school assignment so please don't ask. I would like to produce a list of null terminated strings that I plan to use to test a hash function. Unfortunately I am a bit stumped as what would be the best way to create such a list. The algorithm is as follows: 1. Start with a string containing only a space. 2. Increment the first character in the string. 3. If the value of the first character is 127 (DEL) then set it to 32 (space) and increment the next character (repeat this step if that character is 127). 4. print out the string. 5. goto step 2. I know, Recursion is screaming at me to use it. Problem is, how? I am getting stuck in the wind-up section. (That and the fact that Visual C++ is giving me access violations) My other question is, does anyone else know another way? Eventually I hope to use this to create strings at least 100 chars long (possibly 1000). Could someone tell me if 100 levels using recursion cause a stack overflow? Thanks in Advance David Mcken __________________________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo http://search.yahoo.com |
|
From: <ten...@ne...> - 2003-07-30 16:37:37
|
In C code the variables have to be declared at the top of the function,
and in C++ it can happen anywhere. And Mr Darío Peralta has it with a
source compiled as C.
>
>
>> From: "Dario Peralta" <do...@ho...>
>> To: dev...@li...
>> Subject: [Dev-C++] Weird parse errors...
>> Date: Wed, 30 Jul 2003 00:05:10 -0400
>>
>>
>> I'm using Dev-C++ 4.01 on a Win98se machine...
>>
>> And I'm wondering why I always get a parse error when I try to create
>> a variable or an array after doing anything other than creating vars
>> and arrays... for example:
>>
>> int main(void)
>> {
>> int i, n, m;
>> /* insert whatever code: functions, meaningless loops, whatever */
>> int a;
>> return 0;
>> }
>>
>> will always give me an parse error on the line "int a;" is on... why
>> is that?
>>
>> thanks in advance...
>>
>> adios,
>> dario.
>> --------------------------------------------------------
>> It's time to toss the dice and hope that chance rolls in our favor.
>>
>> _________________________________________________________________
>> The new MSN 8: advanced junk mail protection and 2 months FREE*
>> http://join.msn.com/?page=features/junkmail
>>
>>
>>
>> -------------------------------------------------------
>> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
>> Data Reports, E-commerce, Portals, and Forums are available now.
>> Download today and enter to win an XBOX or Visual Studio .NET.
>> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>>
>> _______________________________________________
>> Dev-cpp-users mailing list
>> Dev...@li...
>> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> _________________________________________________________________
> Tired of 56k? Get a FREE BT Broadband connection
> http://www.msn.co.uk/specials/btbroadband
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: <ten...@ne...> - 2003-07-30 16:27:16
|
You've not allocated memory for buf.
You can do one of two options:
A) Declare an statically allocated array, such as char
buf[MAX_STRING_LENGTH_YOU_EXPECT];
or
B) Declarea a pointer to char as you do char *buf; and then allocated
eough memory to it buf = new char[MAX_STRING_LENGTH_YOU_EXPECT]
However, let's make some comments about this program (it's an example
from a book on using pointers?):
After you have assigned each cstr member of each str_ex array member,
all the members will have the same string. Why? Because you input an
string in buf and then you pass its memory location to the cstr member
(a pointer is a variable which value is a memory location). So all
str_ex array member will have their cstr member pointing to the same
memory location, so each time you change the string at buf you are
changing the string at that memory location and being that the same
memory location cstr are pointing to, all them haveit changed to the
same string.
If you want input different strings to each str_ex member array, then
you shall
A) Allocate memory directly to each struct member (str_ex[x].cstr = new
char [MAX_STRING_ETC]; and don't forget free the memory with delete[]
str_ex[x].cstr). This would means this couple of cycles:
for (int i = 0; i < 12; i++) /**of course, you do this cycle if you want
to input the strings for all array members one after the other, if not
you do the line below as many times you need with the valueas as needed**/
str_ex[i].cstr = new char[MAX_ETC];
and before the end of the program
for (int j = 0; j < 12; j++)
delete[] str_ex[j].cstr;
And for each x member array do cin >> str_ex[x].cstr;
B) The other way, which would make you achieve better memory usage
(depending on how many str_ex array size, value of MAX_ETC, and how
they'll be used after input is no more needed) would be using the buf
as intermediate, so you can do something like this.
buf = new char[MAX_ETC];
for (int i = 0; i < 12; i++){ /**Same comment as the previous option**/
cin >> buf;
str_ex[i].cstr = new char[function_you
_define_to_calculate_string_length_including_null_character(buf)];
strcpy(str_ex[i].cstr, buf);
}
So, now each str_ex array member has an cstr member pointing to its own
memory location, which is different for str_ex, and so you can change
them individually.
When you have finished inputting strings
delete[] buf;
then you work with str_ex array.
And it the end you make the same cycle as the previous option.
P.D. - As you gave no information about the expected and unexpected
behaviours, I cover the two options I can think about: that either you
get memory errors (and surely you'll get them) and you expect to change
array members individually and they're changed all them as one.
dawood wrote:
> Can anybody let me know, why the below code is not working correctly.
>
> #include <iostream.h>
> #include <stdlib.h>
>
> int main()
> {
> struct str_misc {
> char* cstr;
> };
> str_misc str_ex[12];
> char* buf;
>
> cin>>buf;
> str_ex[0].cstr= buf;
> cout<<str_ex[0].cstr<<"index=0"<<'\n';
>
> cin>>buf;
> str_ex[1].cstr= buf;
> cout<<str_ex[1].cstr<<"index=1"<<'\n';
>
> cout<<str_ex[0].cstr<<" repeat index=0"<<'\n';
> cout<<str_ex[1].cstr<<" repeat index=1"<<'\n';
>
> system("PAUSE");
> return 0;
> }
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|