|
You're overwriting hiddenword when you call the cin.getline() function, among other problems.
What you need to do is get the arg in a separate char array and compare that to hiddenword using strcmp or something similar.
This is how I would do it:
int main()<br />
{<br />
const int MAX_SIZE=100;<br />
char hiddenword[MAX_SIZE]; <br />
char typedword[MAX_SIZE];<br />
sprintf(hiddenword, "secret");<br />
printf("Type the word: ");<br />
cin.getline(typedword, MAX_SIZE);<br />
if(strcmp(hiddenword, typedword)){
printf("That is an incorrect word...try again\n");<br />
}<br />
else{<br />
printf("Congratulations! You figured out the secret word!\n");<br />
}<br />
system("pause");<br />
return 0;<br />
}
KR
|
|
|
|
|
As an aside, you're not using C, because you use cin. I'd recommend moving all this code to use C++, for example, using cout instead of printf, and std::string instead of char arrays.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
When I run a module using ShellExecuteEx() i get access to two Handles, a hInstance and a hProcess. How can I use either at a later stage to determine whether the module is still running, How can I use either to kill the instance of the module that ShellExecuteEx() started.
Regards
LateNightsInNewry
|
|
|
|
|
If you want to kill the process, look at this article here.
I'm not sure about how to determine whether the module is running :s sorry
Hope this helps!
--PerspX
|
|
|
|
|
LateNightsInNewry wrote: How can I use either at a later stage to determine whether the module is still running,
The hProcess member (assuming you've used the SEE_MASK_NOCLOSEPROCESS flag) of SHELLEXECUTEINFO
can be used in a synchronization wait function - it will be signaled when the process terminates.
// polling method - wait timeout is 0
if (WAIT_OBJECT_0 == ::WaitForSingleObject(ShellExecuteInfo.hProcess, 0))
{
//process has ended
}
A process should be allowed to terminate normally. If you absolutely must terminate it from
another process you can use TerminateProcess with the same handle as above. Remember you
don't know the state of the other process when you do this so data loss can occur. It's
much better to get the other process to terminate itself normally if at all possible.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks for the help Mark, Tried it, works as advertised. I understand your remark about processes terminating itself normally. I would use the Terminate Process on this occasion as a last resort, if the overnight housekeeping task which was started, and normally completes in minutes, hangs and is still active after several hours, potentially locking users out the next morning.
Thanks again,
LateNightsInNewry
|
|
|
|
|
I am having a problem getting my project to load an icon on VS 2005, VC++.net
AfxGetApp()->LoadIcon(IDI_SIMLEY) There is nothing wrong with this function cos IDI_EXCLAIMATIN work fine. But I am not too sure about the .rc script.
afxres.rc has one line that is
AFX_IDI_STD_FRAME ICON "smiley.ico"
and resource.h
#define IDI_SIMLEY (LPCTSTR)101
Clicking on the RC shows that the icon is there fixed to AFX_IDI_STD_FRAME, instead of the icon the window icon displays (which is the default icon)
|
|
|
|
|
IDI_SIMLEY
AFX_IDI_STD_FRAME
I see different IDs there....which one is correct?
LoadIcon() isn't enough to set a window icon.
You need to call CWnd::SetIcon() with the loaded icon's HICON.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
IDI_SIMLEY is in the include file which goes like
#define IDI_SIMLEY 101
while AFX_IDI_STD_FRAME is in the .rc file. I am using AfxGetApp()->LoadStandardIcon in the Create ( NULL, "windows",........) function which is part of CFrameWnd.
How do I use CWnd::SetIcon in this case?
|
|
|
|
|
I'm not sure how you are using LoadStandardIcon() in CFrameWnd::Create(). None of the Create()
parameters take an HICON.
Regardless, LoadStandardIcon() loads system icons. To load an icon from your app's resources
you need to load them yourself.
Here's one way to change a window's icon after it has been created:
if (MyFrameWnd.Create(NULL, "windows",........))
{
HICON hIcon = AfxGetApp()->LoadIcon(IDI_SIMLEY);
MyFrameWnd.SetIcon(hIcon, TRUE);
}
Another method is to use a custom window class instead of the default MFC window class and
specify an HICON in that window class. A window created using that windowclass will use that
icon by default.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I have a service that runs at idle dispatch priority because it is a continuously running background process that monitors certain resources. It starts when the machine is booted and ends when the machine is shut down.
As a result of being run at idle dispatch priority it accumulates a lot of page faults. Being a background process this performance hit is not a problem but I am concerned that the page fault number will climb to a point where it may cause problems, both perceptually and possibly to processes monitoring activity.
Is there a way of resetting page fault count periodically without going through the exercise of unloading and reloading the service just to reset the counter?
|
|
|
|
|
#ifndef GLINIT_H
#define GLINIT_H
#ifdef _EXPORT
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
GLAPI void GLInit()
{
int i;
i++;
return;
}
#endif
Can someone tell me why this is not allowed in a header? I want to simply include this header and have the includer call GLInit().
The error I get when compiling with VC 2005 is:
error C2491: 'GLInit' : definition of dllimport function not allowed
I'd like to add that there is no practical reason for me to do this, because I can simply include the function without exporting, however, I'm playing around with exporting and can't figure out the problem.
|
|
|
|
|
try this:
#ifdef _EXPORT
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
#ifdef _EXPORT
GLAPI void GLInit()
{
int i;
i++;
return;
}
#endif
you should move your implementation to a .cpp - File or use the macro from above.
|
|
|
|
|
Yes, but what if I want to include a global function? If I were to write the function in a .cpp, I'd have to include the .cpp. I don't think the file extension makes any difference at all, but it just feels weird including a .cpp.
|
|
|
|
|
The header file should just contain the declaration (prototype) for the function.
The actual definition of the function should be moved out of the header to a single .c/.cpp file.
That c/cpp file should only be in the dll project. The header can be used in the dll project
and app projects which use the dll.
#ifndef GLINIT_H
#define GLINIT_H
#ifdef _EXPORT
#define GLAPI __declspec(dllexport)
#else
#define GLAPI __declspec(dllimport)
#endif
GLAPI void GLInit();
#endif
void GLAPI GLInit()
{
int i; <code><-- i is uninitialized!</code> :)
i++;
return;
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
|
I create project that has view class derive from CFromView and I put combo control on this view.
I need to AddString at the point when the main windows create.
I try to put it in WM_CREATE functine and PreCreateWindow function but I got "Assertion fail".
Please advise me,What's message function use for this issue.
|
|
|
|
|
It won't work in PreCreateWindow because the window object (HWND) for the control has not been
created yet.
Any time in OnCreate(), after the base class OnCreate() has been called, it should work
(unless you are manually creating the combobox, in which case any time after you create the
control's window).
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hello,
can anyone help me ???
I want to get listing of active com port name to be displayed for selection ... as in like that hyper-terminal where you select the com port for use. virtual com port...
what`s the command code for getting the list like directory so i can display that out for selection ???
Thanks !
|
|
|
|
|
Just for idea, you can see Teraterm terminal software for which source available at the end of its home page[^]
Best Regards,
Suman
|
|
|
|
|
What about the Win32_SerialPort WMI class?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Nameste Guruji's
I am making an app... in VC++ in which i need to open notepad and MSWord file at VC++ form , Notepad file is open but msword file not open , my code is below
void CSearch::OnButtonCal()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
WinExec("notepad.exe",SW_SHOW);
}
Its work properly
But when i try to open ms word or winword file with below code its not working properly
void CSearch::OnButtonCal()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
WinExec("winword.exe",SW_SHOW);
}
can any one told me what is mistake here.
Plz told me its correct solution as soon as possible
Regard's
Kaushik
|
|
|
|
|
Probably Winword.exe is not in the standard search path as it's an installed application. Notepad.exe lives in the Windows folder so it can always be found.
You need to add a path to the filename. e.g.
WinExec("c:\\Program Files\\Office\\winword.exe",SW_SHOW);
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Hi
i am making an application in vc++ according to client requirment we have to save .doc file in mysql database (.doc file is just copy and paste in an edit box)
I use BLOB mysql data type for that .
but when i submit form we can not save a large .doc file in data base
My question is that can i use any property or any method in vc++ for edit box so that we can save more data at a time
Please guide me in this for solving this problem
Regard's
Kaushik
|
|
|
|
|
Y_Kaushik wrote: ...we can not save a large .doc file in data base
Can you save smaller files?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|