system() command in C language is not working

January 28, 2011 at 07:14:19
Specs: Windows XP, 512 MB
i have written this code in C++ to make a program that takes a character as an input from the user and matches it with the ASCII code of "A". if it is matched (user entered "A"), the system should hibernate as i have used the system() function with hibernation command. The program is compiled , but the computer is not hibernating on fulfillment of the condition(i.e. system() command is not working. my operationg system is windows XP. can anyone help. i would be pleased.

#inlcude <stdio.h>
#include <conio.h>
#include <process.h>
#include <stdio.h>

char x;
printf("Enter any character");
if (x==65)
system("C:\WINDOWS\SYSTEM32\rundll32.exe PowrProf.dll, SetSuspendState");

See More: system() command in C language is not working

Report •

January 28, 2011 at 07:59:35
I'd suggest that you set the return value of the "system" call to a variable, so that you can inspect it, then use a debugger to single-step through the code to see exactly what is happening. I presume that you realize that scanf won't read anything until you press the "Enter" key.

Report •

March 6, 2011 at 09:32:06
I have already tried this and the return value is -1. can you tell me further what shall i do?

Report •

March 6, 2011 at 15:35:24
i have written this code in C++
It's actually C, not C++. You do not use any C++ objects/features, and it's non-conformant C++, but valid C.

the return value is -1.
Check errno for more information on what's going wrong.

Obvious question: You're already using Windows specific features, why not just call the function directly, instead of going though system()?

How To Ask Questions The Smart Way

Report •

Related Solutions

Ask Question