Thread: C program to shutdown or turn off computer for windows xp

  1. #1
    Registered User Rakesh o_O's Avatar
    Join Date
    Jun 2012

    Question C program to shutdown or turn off computer for windows xp

    I'm new in programming world and facing a problem..when i compile the given code in "turbo c++ 4.5" its gives an error like this.."undefine symbol_system in module NOAME00.CPP"...need help to correct this.

    #include <stdio.h>
    #include <stdlib.h>
        char ch;
        printf("Do you want to shutdown your computer now (y/n)\n");
        if (ch == 'y' || ch == 'Y')
            system("C:\\WINDOWS\\System32\\shutdown -s");
        return 0;

  2. #2
    Registered User
    Join Date
    May 2012
    Arizona, USA
    Quote Originally Posted by Rakesh o_O View Post
    [B]when i compile the given code in "turbo c++ 4.5"
    I found your problem. Get a real C compiler, not "Turbo" anything. The "system" function has been standard since C89 at least.

  3. #3
    Registered User
    Join Date
    Sep 2006
    "system" has worked since Turbo C 1.01, so the above is incorrect.

    You are compiling your program with a cpp filename extension. That means you're really creating a C++ program, not a C program. For a C program, change your file extensions to dot c, instead.

    Check your compiler and see what header you need to include, for "system". With Turbo C 1.01, I had to add the TC and TC/BIN directories, into the path for XP (check your windows help for how to change your environmental variables (one of them is the PATH string).

    Unless you have to use Turbo C or C++, I would DEFINITELY move over to one of the free good and modern compilers (MS, Pelles C, gcc, etc.). Believe me, the difference is like night and day (at least it was for me since I was a die-hard TC 1.01 user). You'll wonder why you didn't change over earlier, even though there is a learning curve to get over.
    Last edited by Adak; 06-29-2012 at 06:00 PM.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Questions of compiler aside, if you can use the WIN32 API, the ExitWindowsEx() function is a better choice than a system() call.

    I'm not sure, given the age, whether Turbo C++ 4.5 allows usage of the win32 API, but more recent and freely available compilers certainly do.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling a program for Mac OSX from a windows computer
    By Jedi Nescioquis in forum Windows Programming
    Replies: 1
    Last Post: 02-13-2009, 03:06 PM
  2. I cant turn my Computer off
    By h3ro in forum Tech Board
    Replies: 9
    Last Post: 03-25-2008, 06:51 PM
  3. How to shutdown a computer?
    By Digga in forum Windows Programming
    Replies: 7
    Last Post: 05-02-2005, 08:20 PM
  4. Shutdown computer
    By Kinasz in forum Tech Board
    Replies: 2
    Last Post: 03-17-2003, 12:55 AM
  5. make windows shutdown
    By GravtyKlz in forum Windows Programming
    Replies: 1
    Last Post: 03-12-2003, 11:25 AM