Click here to Skip to main content
15,910,411 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
General. Pin
hssaroch3-Apr-05 23:41
hssaroch3-Apr-05 23:41 
GeneralRe: Network gaming problem Pin
Alexander M.,4-Apr-05 2:37
Alexander M.,4-Apr-05 2:37 
GeneralSaving a list box or list control data to txt file Pin
shinyhui3-Apr-05 23:33
shinyhui3-Apr-05 23:33 
GeneralRe: Saving a list box or list control data to txt file Pin
toxcct3-Apr-05 23:53
toxcct3-Apr-05 23:53 
GeneralRe: Saving a list box or list control data to txt file Pin
RobJones4-Apr-05 5:44
RobJones4-Apr-05 5:44 
GeneralRe: Saving a list box or list control data to txt file Pin
shinyhui4-Apr-05 14:17
shinyhui4-Apr-05 14:17 
GeneralTELNET FAILURE!!! URGENT HELP NEEDED!!! Pin
URagavSouth3-Apr-05 23:32
URagavSouth3-Apr-05 23:32 
Generalvalidation Pin
mpapeo3-Apr-05 23:14
mpapeo3-Apr-05 23:14 
Pliz help me to validate my input in my program below.I want to accept the integer input only but not characters, how do i do it because i used dafault in my case statement. If i enter characters the program crushes.

#include <stdio.h>
#define _WIN32_WINNT 0x0400
#define WINVER 0x0400
#include <windows.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <imagehlp.h>
#include <stdlib.h>
typedef struct _iobuf FILE;
#include <assert.h>
#include <sys types.h="">
#include <sys stat.h="">
int menu(void)
{
int choice;
printf ("\n");
printf ("*****************************************\n");
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");
printf ("=========================================");
printf ("\n=\t 1: Create a process \t\t=");
printf ("\n=\t 2: Suspend the process\t\t=");
printf ("\n=\t 3: Resume process \t=");
printf ("\n=\t 4: Shutdown the process \t=");
printf ("\n=========================================\n");
printf ("\n");

printf("\nEnter choice (1-4): ");
scanf("%d", &choice);
return choice;
}
int main(int argc, char **argv)
{
PROCESS_INFORMATION pi; /* filled in by CreateProcess */
STARTUPINFO si; /* startup info for the new process*/
HANDLE hProcess;
DWORD lpAddr = 0;
TCHAR lpApplicationName[_MAX_PATH]="";
int result;
char ans [4]="";
int choice;

while((choice = menu())!=5)
{
switch (choice)
{
case 1:

GetStartupInfo(&si);
lpAddr = 0;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
printf("Enter process you want to execute: ",lpApplicationName);
scanf ("%s",lpApplicationName);
printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID

CreateProcess(NULL, /* lpApplicationName */
lpApplicationName, /* lpCommandLine assumes to use curent process directory*/
NULL, /* lpsaProcess */
NULL, /* lpsaThread */
FALSE, /* bInheritHandles */
CREATE_NEW_CONSOLE, /* dwCreationFlags */
NULL, /* lpEnvironment */
NULL, /* lpCurDir */
&si, /* lpStartupInfo */
&pi /* lpProcInfo */
);
hProcess = pi.hProcess;
printf("New Process ID: %d ",pi.dwProcessId);
printf("has started \n");
break;
case 2:
SuspendThread(pi.hThread);// identifies thread to suspend
break;
case 3:
ResumeThread(pi.hProcess);
break;

case 4:
printf("\nYou are about to terminate a running process, do you want to continue ( y or n) ");
scanf ("%s",ans);
result = strcmp(ans,"y");
if (result==0)
{
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate
GetLastError();
}
break;
default:
printf("\nInvalid choice: ");
}
}
return (0);
}

-oam-
GeneralRe: validation Pin
Gary R. Wheeler4-Apr-05 1:57
Gary R. Wheeler4-Apr-05 1:57 
GeneralRe: validation Pin
David Crow4-Apr-05 2:55
David Crow4-Apr-05 2:55 
GeneralRe: validation Pin
mpapeo4-Apr-05 7:51
mpapeo4-Apr-05 7:51 
GeneralRe: validation Pin
mpapeo4-Apr-05 10:30
mpapeo4-Apr-05 10:30 
GeneralRe: validation Pin
David Crow4-Apr-05 10:38
David Crow4-Apr-05 10:38 
GeneralRe: validation Pin
mpapeo4-Apr-05 11:01
mpapeo4-Apr-05 11:01 
GeneralRe: validation Pin
mpapeo4-Apr-05 12:01
mpapeo4-Apr-05 12:01 
GeneralRe: validation Pin
David Crow4-Apr-05 17:03
David Crow4-Apr-05 17:03 
GeneralRe: validation Pin
David Crow4-Apr-05 17:01
David Crow4-Apr-05 17:01 
Generalglobal variables in dynamic link library Pin
arthi_mclt3-Apr-05 23:05
arthi_mclt3-Apr-05 23:05 
GeneralRe: global variables in dynamic link library Pin
Alexander M.,4-Apr-05 2:53
Alexander M.,4-Apr-05 2:53 
GeneralText display with CHtmlView Pin
lordguid3-Apr-05 22:48
lordguid3-Apr-05 22:48 
GeneralRichEdit and Console Pin
AdyOS3-Apr-05 22:36
AdyOS3-Apr-05 22:36 
GeneralRe: RichEdit and Console Pin
toxcct3-Apr-05 22:39
toxcct3-Apr-05 22:39 
GeneralRe: RichEdit and Console Pin
AdyOS3-Apr-05 23:00
AdyOS3-Apr-05 23:00 
GeneralRe: RichEdit and Console Pin
toxcct3-Apr-05 23:22
toxcct3-Apr-05 23:22 
GeneralRe: RichEdit and Console Pin
S. Senthil Kumar3-Apr-05 23:24
S. Senthil Kumar3-Apr-05 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.