|
Oops! I responded into the wrong thread. Sorry for any confusion caused.
|
|
|
|
|
hello
i was wondering what was wrong with the following code:
lr = strlen(menu);
lr is an intiger,... the reason i want to use strlen is because:
my program accepts a letter for you to tell the computer what you want... when you put in more than one character into the cin << menu, the program breaks down and goes non-stop through the main loop.
thanks for your help!
~SilverShalkin
|
|
|
|
|
The problem is you should be using C++ instead of C. Make menu a std::string and use menu.length() to find out how big it is.
Otherwise, if menu is a char array, try strlen(&menu[0]); It's probably something like that, but I'm not sure - I don't program much C.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
The problem is you should be using C++ instead of C. Make menu a std::string and use menu.length() to find out how big it is.
Hmmm, not everyone want to use STD, I don't like it and try to avoid it when I can. And depending on what you are programming it's not always a good idea. I spend a lot of my time programming server applications where I need all the speed I can get, and a std::string is way slower than a char array
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Anders Molin wrote:
Hmmm, not everyone want to use STD, I don't like it and try to avoid it when I can.
Why don't you like it ?
Anders Molin wrote:
depending on what you are programming it's not always a good idea.
I have no doubt, but while that may be the case, overall, too many people use clunky C style strings and so on IMO. They are not safe, they are hard to use, but yes, they are faster in some instances. My main beef is that Universities do not teach C++, they teach C with classes.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
Why don't you like it ?
Hmmm, I think most of STL makes things hard to use, yes, I really do...
The strings are slow, the documentation sucks, and I don't like the way you use it...
Christian Graus wrote:
I have no doubt, but while that may be the case, overall, too many people use clunky C style strings and so on IMO. They are not safe, they are hard to use, but yes, they are faster in some instances.
Well, C strings are not that hard to use, sure, there's a lot more that can go wrong, but there's also lot's of bennefits
Christian Graus wrote:
My main beef is that Universities do not teach C++, they teach C with classes.
I don't know about what they teaches, but I'll agree with you on that one
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Anders Molin wrote:
Hmmm, I think most of STL makes things hard to use, yes, I really do...
The strings are slow, the documentation sucks, and I don't like the way you use it...
I dunno about the string speed, I've never had to stress it. Beyond that, the docs in MSDN suck for a reason, but there are plenty of good books out there, and std::string is a long way from being a central feature. What do you use for containers then ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
What do you use for containers then ?
Well, a long time ago when I first tried templates I wrote a template-based list which I today use for almost everything. It's small fast and works for everything I need
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Well, if you don't need a variety of containers or built in algorithms then I suppose you've duplicated the idea of the STL all by yourself
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
|
I don´t really understand what are you trying to acomplish, but strlen counts the characters on the string until it finds a '\0', like "stan\0", so, if menu is declared as a char, there is no room for the ending mark (\0) and it keeps reading your program memory until it finds an invalid address or an address that has a 0 value!
hope this helps!
Gabriel
don´t worry drink happy
|
|
|
|
|
Ok... i just jumped on to ask another question and saw the continuation of this question first off... char is not a pointer. its a character.... "wait i think i just figuered out my problem with my program " anyways... they reason i want to do it is to make the user of the program not beable to enter more than one char... because if you do, then problems accure "thats the thing i just figuered out"
if i just make it for that the char is bigger like char[10] or somthing,... than would you run into problems entering more than one character? "most likly not." but the question remains.
ok cristian, im going with you on this one the problem is: how do you declare my char menu as a std::string?
Thanks everyone for your posts... "see you in the next question "
~SilverShalkin
|
|
|
|
|
hey folks...
sorta new to COM programming and i have a question. i've read in several places that it may be a bad thing to call CoInitialize\Ex in a .dll. currently, i have a dll which incorporates DirectShow to play files, navigate streams.. etc. i instantiate COM directly in this dll for the purposes of calling DirectShow interfaces. however, i do not do this in the dllmain function. the calling app, which includes this dll statically at link time, does not have it's own CoInitialize\Ex call. Lately, i've been experiencing strange, erratic behavior in the application, at times causing complete system failure. so i was wondering, is it generally a bad thing to call CoInitialize\Ex within a dll? or doesn't it matter..
thanks..
|
|
|
|
|
Is it bad? Not inherently. But that isn't the whole story.
In an application controlled 100% by you, then you can place your CoI/CoU in an OCX if you want to. As long as you follow the proper rules nobody cares.
But, if you aren't in control of the main application, then it is a VERY VERY bad idea to call CoI/CoU from any thread NOT MANAGED by you. If you create a thread, then feel free to call CoI/CoU in that thread all you want.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Again with the modeless....
I asked how to correct the layering of modeless windows and the "parent" CMainFrame application dialog. Thanks for answers, but...
NOW I have the question of multiple modeless dialogs and the same layering issues.
The focus changes ok between the modeless dialog and the CMainFrame dialog (the one with the menu/toolbars). The layering between (sub) modeless dialogs does not work as expected - the dialog with focus does not rise to top above other modeless dialogs
Help
Thanks.
|
|
|
|
|
Are you sure that all your modeless dialogs use the desktop as their parent window?
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
In order to get tabbing and focus changes to work correctly in this case, you need to set the 'Control' style in the modeless dialogs (the children), and the 'Control parent' style in the parent dialog.
We use this approach in a product where I work.
Gary R. Wheeler
|
|
|
|
|
I have a dialoge with this UI:
----------------------------------------
| My Dialoge |
----------------------------------------
| ---------- |
| |tree | Name: the name |
| |control |description:a description |
| | | |
| | | |
| | | |
| | | more stuff |
| | | |
| | | |
| | | |
| | | |
| ---------- |
----------------------------------------
The box on the left is a tree control.
The description can be a few words or an entire paragraph, forcing me to put more stuff many lines below the description. I was wondering it its possible to dynamically change the position of more stuff based on the number of lines that the description takes up...well im pretty sure that can be done but can you find out the number of lines that the description is taking up?
-Raffi
|
|
|
|
|
Have a look at the CDC::DrawText() function and the DT_CALCRECT flag
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
If a man is standing in the middle of the forest speaking and there is no woman around to hear him...is he still wrong?
|
|
|
|
|
thx for the help
-Raffi
|
|
|
|
|
Hi:
In a CFormView-derived view, I can change control colors by handling WM_CTLCOLOR messages.
What can I do to change control colors for a CView-derived view?
Thanks
|
|
|
|
|
Whether CFormView or CView derived does not matter, simply override OnCtlColor(...) [which is called when a WM_CTLCOLOR message arrives].
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Like Nish said, this is where you want to do it. You can use the nCtlColor variable to check for what kind of control it is and then send back a different HBRUSH for different controls to control the color.
|
|
|
|
|
Hi.
I am new to winsock program and has began study from Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohlund.
I am trying to get a code to basically resolve a hostname to its ip address. For example:
-----
user input: www.microsoft.com
app output: 207.46.230.220
-----
I am able to get the calculation above working using older winsock 1.1+ tool including the use of structure hostent, gethostbyname(), and inet_ntoa().
However, in their book, Jones and Ohlund recommend using the newer winsock tools including getaddrinfo() and getnameinfo(). I cannot figure out how to extract the corresponding IP address from a hostname. Here is the code:
-----
int rc = 0;
addrinfo hints, *result = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
if (getaddrinfo(rHName, "21", &hints, &result) != 0)
return false;
else
{
// This is where I need help getting the IP address
m_sIP = (reinterpret_cast<sockaddr *="">(result->ai_addr)->sa_data());// ->sa_data(); // inet_ntoa(*(reinterpret_cast<in_addr *="">(host->h_addr)));
return = true;
}
-----
In the code above, m_sIP is a character array. What do I have to cast result->ai_addr in order to access the IP address?
Thanks,
Kuphryn
|
|
|
|
|