Change your function to this and tell me what happens.
int validateMonth(unsigned int month)
{
if(month<0 || month>12) /* flag 1 for true*/
{
return 0;
}
return 1;
}
Change your function to this and tell me what happens.
int validateMonth(unsigned int month)
{
if(month<0 || month>12) /* flag 1 for true*/
{
return 0;
}
return 1;
}
I think the difference is the syntax.
There is more than syntax difference.
Object Oriented Programming Support.
template support.
are two of the most important IMHO that come to my mind.
But the STL in c++ is supposed to make things easier than C when you learn it. :lol:
And even if you are creating programs for commercial use. The STL is tested extensively, and safe to use than your own customized lists, hash-tables...I dont know about the performance comparisons, but they were really fast for my requirements. I think that unless you are writing a program to implement an example of a list, hash-table..., you better use the stl::list, stdext::hashmap ...
Tell me what is expected as output of this validateMonth function. What is expected for correct input, and what is expected for incorrect input?
char* validateMonth(unsigned month, char* prompt)
{
/*unsigned m = 0;*/
int valid = 0;
char *m;
/*int flag = FALSE; */ /* false value*/
if(month<0 || month>12) /* flag 1 for true*/
{
printf("Month error 0 or less or equal to 12 please\n");
getUserInput(prompt);
valid =1;
}
return m;
}
I find it strange that you dont get a compiler error at this line.
tmpMonth = validateMonth(valMonth, prompt, result);
Have you defined two
validateMonth
functions?
Post the code.
tmpMonth = validateMonth(valMonth, prompt, result);
What is this parameter result
that you are passing? It is not in the declaration or the definition of the function.
Also the
return m;
line in
validateMonth
returns null as you are not assigning any value to m.
Well I took a look at your problem. Regarding the bisection-method looks as if you dont have an idea with what you are doing. I will give you a brief algorithm here and try to see if you can understand it and implement it.
Eq is x[ 1 + k1*n1/(1 + k1*x ) + k2*n2/(1 + k2*x ) + ... km*nm/(1 + km*x ) - L = 0
The idea of the bisectional method is to first find two values of x so that the left part of the above equation is positive for one of those values and negative for the other value.
If you take x = 0 as one of the values, by substituting x = 0 to the above equation, the left side will be equal to -L.
So now we have to find another value of x such that the left part of the equation is of opposite sign of -L.
To do this
for ( x = 1 ; x < INT_MAX; x++ )
{
value = x[ 1 + k1*n1/(1 + k1*x ) + k2*n2/(1 + k2*x ) + ... km*nm/(1 + km*x ) - L ;
if ( ( (-L ) > 0 and value < 0 ) or ( ( (-L ) < 0 and value > 0 ) )
{
secondvalue = x ;
break;
}
// Maybe -x has a value where the sign changes
value = (-x)[ 1 + k1*n1/(1 + k1*(-x) ) …
Well, according to the error messages you havent given all the required parameters. Did you check that out?
i dont know how to set the pointer back to the beginning of the text file..
Use SetFilePointer to move the file pointer of an open file.
Thank you very much. That was perfect.
Thanks for looking in to it.
I get the output. But after printing the last word, it just hangs like as if expecting another string too. I tried running it under a debugger and had a look at the contents of query
. I couldn't see the values, only "badptr".
My environment is
Operating System Windows XP.
Compiler Visual C++ Express 2005
Can anybody please tell me what is wrong with this piece of code?
std::string query;
std::cout << "Enter the Query String :";// Type something with spaces here. e.g ( "financial instruments being traded on the American stock exchange" );
while (std::cin >> query )
{
std::cout << query <<std::endl;
}
The objective is to tokenize the string at whitespace as it is read from cin.
e.g the output should be
Enter the Query String :financial instruments being traded on the American stock exchange
financial
instruments
being
traded
on
the
American
stock
exchange
And you will probably also have to download the Windows SDK free from Microsoft.
As he says that it worked with Visual Studio 6.0, most probably some form of that file should be in his computer already. Good to have the latest version of the PSDK though. Especially with the brand new compiler. :D
I cant see the quote box in my home computer but can see it in my work computer. Both use LCD monitors. The new one looks good. Pity that I cant see it at home though.
Okay. Changed the constrast, actually reduced it to 0. Now I can see the quote box at home too. :D
1>LINK : fatal error LNK1104: cannot open file 'odbc32.lib'
This means that the linker cant find this library file. Set the library files path of Visual studio to the folder that this is in. Most probably that folder will be the Lib directory of the Platform SDK installation.
Heck, I wouldn't complain if some chick added me to MSN. I am enabling my contact options right now...:mrgreen:
It worked, it worked. Yay
Bah! It's usually NOT chicks (is the problem) ;)
:sad:
I am not 100% sure about this, but I dont think you can do that. Maybe someone who has more experiance in network programming will disagree, but out of the Socket Models that I have used upto now, when you get a connection request, you can only tell to what socket is that request made. There is no way of differentiating from which port-number.
By the way, why do you need 15 different port numbers? That means you are trying to use 15 different protocols. What are you trying to do?
I haven't done it, but I dont think that it should be much different than listening in a single port...Just create SocketNumber1 and bind it to portnumber1, create SocketNumber2 and bind it to portnumber2, and listen on both sockets. Depending on the Socket I/O Model, you will get which request comes to which socket. Give what you have tried so far, and maybe someone will be able to see what you are doing wrong.
I know that I get added to people's MSN Messenger, and IM's requesting help on a personal level ...
Heck, I wouldn't complain if some chick added me to MSN. I am enabling my contact options right now...:mrgreen:
There has got to be enough sample code in the internet you know, if you only google for it..
And, btw, have you heard for a coder SnapDragon? He's such a good competitior that he recently stared in the film 'Rent'.
This is out of C/C++. But do you mean the Musical called Rent? Starring Mark Cohen?
You can do that by just changing these lines.I am not giving you the answer because if you wrote the above program yourself, you can surely do this part using the hint I have given you.
count = 1;
count = count + 1;
// program computes the sum of all even numbers from input number
This part of the objective does not make sense to me. Care giving a sample input number, like 12, and explaining what the expected result would be?
Right now it gives the result
1 + 2 + 3 + ... + 11 + 12 = 78
for the input of 12.
You want to add a "Event Handler" for the event of pressing a Tab key or Return key?
What Compiler of VC are you using?
Word wrap would defeat the purpose of code tags.
Feared as much. :sad: Guess the only option is to copy it to notepad and view it there. :cheesy:
Thanks Dani. :thumbs up:
I get it now. Must have been hard to create that example just for me, though :)
Since code tags preserve line length, it requires horizontal scrolling so that it doesn't stretch the layout of the page.
So I guess that means a Word Wrap option is also out of the question?:sad:
Thanks a lot.
Thanks for the quick reply but I am afraid I dont see how it applies to vertical scroll bars. Sorry if it was explained in your reply.
I have seen that even for code with a small number of lines, vertical scroll bars are added and we have to scroll to see all of it. Also this restriction does not seem to apply for other tags, e.g. [[/B][B]quote][/quote[/B][B]] tags. I think that it would make the reading of code much easier if the scroll bars were either taken away if possible, or made to appear after a much larger number of code lines.
I cant see the quote box in my home computer but can see it in my work computer. Both use LCD monitors. The new one looks good. Pity that I cant see it at home though.
I don't have a problem described in reply #10, but the one in previous reply #9. And yes, I did follow the steps in that M$ link about how to set up the compiler for windows applications -- that's not my problem. But thanks anyway.
I was just checking your settings just in case. I have done only those modifications and I can run this code without any problem.
#include <windows.h>
int main()
{
MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK);
return 0;
}
Therefore a solution doesnot come to me right now. Sorry about that.
Pffffffff, man oh man, finally, it's working, Narue and especially WolfPack, thanks for your patience, really appreciated :!: :!:
No big deal. Narue made a big breakthrough noticing the _main part in the linker errors. I only saw the first linker error with _Winmain@16.
Can I ask WolfPack, do you have a manual from Visual C++ 2005? If not, how do you know these solutions, or is it experience with VC++ 2005?
Pure Experience. I have faced all of your problems some time ago. So it's all coming back to me now.
I have had the same question about how to disable UNICODE settings -- thanks WolfPack for the help. But even after that, I also get the unresolved external MessageBox error. Can't it be used in console applications?? I use it in console apps with VC++ 6.0 compiler without any problems. Maybe we just can't use in console apps with that free Express edition compiler. Otherwise, the other win32 api functions I use (FindFirstFile(), FindNextFile() etc) compile and link ok.
I find no problem in doing it. Have you done the modifications I told JoBe in a previous reply ( Reply Number 10 in this thread )? Can you make GUI Applications in Visual Studio 2005?
Exactly the same problems I went through while I installed Visual Studio 2005 for the first time. Try setting Embed Manifest to No. See attachment.
Euhm, I'm using Win32 Console Application :o
I'm presuming that isn't right :-|
If that's not correct, which one do I have to use then, and also, how do I create this with an empty proj. ????
Options are:
- Class Library
- CLR Console Application
- CLR Empty Project
- Makefile Project
- Win32 Console Application
- Windows Forms Application
- Empty Project
After Selecting Win32 Console Application, you are taken to the Application Wizard. Click Application Settings in it, and you should see 4 options, in which the option "Windows Application" is disabled. It is this option you should choose to build a GUI application. To enable it follow the steps in the link I provided in the previous post.
>error LNK2019: unresolved external symbol _main referenced in function
You're using a console application?
Duh. Yeah. Seems like it.
[Edit]
Okay I think I know what your problem is. Building Win32 Applications is disabled in the Visual Studio 2005 by default. You can build only Console Programs as it is. To create Win32 Applications look at this article by Brian Johnson.
Beats me, it ought to work. Anyway change the Character set to what it was ( Unicode ) and run this code and tell me what happens.
// WinApi.cpp : Defines the entry point for the console application.
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, L"Goodbye, cruel world!", L"Note", MB_OK);
return 0;
}
As for the second problem, there is a drop down box to select the type you are adding the directory. See the attached bitmap.
$(ProgramFiles)\Microsoft Platform SDK\lib ---- To Library Files
$(ProgramFiles)\Microsoft Platform SDK\bin ---- To executable Files
$(ProgramFiles)\Microsoft Platform SDK\include ----- To Include Files
Visual Studio has enabled Unicode support by default. So even though you have written MessageBox, as Narue said, it calls MessageBoxW because of this setting.
Try setting
Project--->Propoerties-->Configuration Properties-->General-->Character Set
to "Use Multi-Byte Character Set" or "Not Set", and compile. It should work.
The usual way programmers tell the compiler to use the Wide String format or not is by setting the #define UNICODE preprocessor switch.
I am not sure if want all 16 Cabinet files. But if you want a customized installation, why not try this option?
Instructions
* To run the installation program over the Internet, choose to download the Platform SDK for Windows Server 2003 SP1 Web Install. The installation program will install the components you select.
EDIT:
I don't understand what I'm doing wrong, I also downloaded the extract winzip and when extracting this, I get the Extract tool, but when I click on this, it comes up and goes down again, do I have to use this tool in a certain way?????
You have a PSDK-FULL.bat file that was extracted from the PSI-FULL.exe. Run it with a target directory to extract. It will call the Extract.EXE file.
What has the documentation got to say about Combo boxes in Borland?
But I cannot use WM_KEYDOWN or something else, because I already use WM_INPUT. I recieve the input with WM_INPUT, not with WM_KEYDOWN.
When user hits ALT key, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYDOWN are sent. But, WM_SYSKEYUP is not sent.
Why?
WM_SYSKEYUP Notification
The WM_SYSKEYUP message is posted to the window with the keyboard focus when the user releases a key that was pressed while the ALT key was held down. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYUP message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.
Why does WM_SYSKEYDOWN is sent twice?
I ran a piece of code and I didnt see this behaviour when I pressed the ALT key. It sent only the WM_SYSKEYDOWN and the WM_KEYUP messages.
ALT Key
Kbd: make=0038 Flags:0002 Reserved:0000 ExtraInformation:00000000, msg=0104 VK=0012
Kbd: make=0038 Flags:0003 Reserved:0000 ExtraInformation:00000000, msg=0101 VK=0012
But I cannot use WM_KEYDOWN or something else, because I already use WM_INPUT. I recieve the input with WM_INPUT, not with WM_KEYDOWN.
Here is what I got for some keys.
DELETE Key
Kbd: make=002a Flags:0002 Reserved:0000 ExtraInformation:00000000, msg=0100 VK=00ff
Kbd: make=0053 Flags:0002 Reserved:0000 ExtraInformation:00000000, msg=0100 VK=002e
Kbd: make=0053 Flags:0003 Reserved:0000 ExtraInformation:00000000, msg=0101 VK=002e
Kbd: make=002a Flags:0003 Reserved:0000 ExtraInformation:00000000, msg=0101 VK=00ff
'K' Key
Kbd: make=0025 Flags:0000 Reserved:0000 ExtraInformation:00000000, msg=0100 VK=004b
Kbd: make=0025 Flags:0001 Reserved:0000 ExtraInformation:00000000, msg=0101 VK=004b
You can see that VK=00FF for the one of the …
But when either Windows, insert, delete, home, end, pageup or pagedown key is pressed, WM_KEYDOWN and WM_KEYUP messages are sent twice. I mean, 2x2=4 times.
So, what about this situation?
All these Keys are Extended Keys. If you read the documentation for WM_KEYDOWN, WM_KEYUP ..., you will see that the 25th bit of the lParam value of the respective message tells you if the key is extended or not. You will be able to check it with an operation like this in the Windows Message loop.
case WM_KEYDOWN:
if ( ( LOWORD( lParam) & 0x01000000 ) == 0 ) // NOt an extended key
{
// Do Processing
}
else //Extended Key
{
//....
}
use the
pRawInput->data.keyboard.Message
field. It returns 0x101 when released and 0x100 ( i think it is 0x100, check the documentation just in case ) when it is pressed. You can use an if condition to check the two.
something like
if ( pRawInput->data.keyboard.Message = 0x100 ) // Pressed
{
// Do processing
}
else
{
//Ignore
}
As for the user keeping on pressing, Maybe checking for consecutive 0x100 values with the same VKey will do the trick.
Try this.
Cells& Cells::operator= (const Cells& cells)
{
resetSize(cells.DEPTH, cells.ROW, cells.COL);
for(int d=0; d<DEPTH; d++)
{
for(int r=0; r<ROW; r++)
{
for(int c=0; c<COL; c++)
{
array[d][r][c] = cells.array[d][r][c];
}
}
}
return this;
}
So a better implementation will be like this.
// if there is no prime number between 1 and num, getMaxPrime() should return a 0.
int getMaxPrime (int num)
{
int maxPrime = 0 ;
for ( int i = num - 1 ; i > 1 ; i-- ) // Since between 1 and num means those numbers are not included
{
if ( isPrime( i ) )
{
return i;
}
}
}
No need for the sqrt part. I was thinking something else. :o
That code is slow; instead start at the top and count downwards.
yeah you are right. Didnt think that much, just wrote the code straight on. If you change the code to
for ( int i = num ; i >= (int)sqrt( num ) ; i-- )
...
the result will be much faster.
Something like this.
// if there is no prime number between 1 and num, getMaxPrime() should return a 0.
int getMaxPrime (int num)
{
int maxPrime = 0 ;
for ( int i = 2 ; i <num ; i++ ) // Since between 1 and num means those numbers are not included
{
if ( isPrime( i ) )
{
maxPrime = i ;
}
}
return maxPrime;
}
ERROR_RESOURCE_TYPE_NOT_FOUND
1813 The specified resource type cannot be found in the image file.
One of the names you have used in the new resource file is different from the one you used yesterday.