Like Tree4Likes
  • 3 Post By christop
  • 1 Post By Adak

C program to shutdown or turn off computer for windows xp

This is a discussion on C program to shutdown or turn off computer for windows xp within the C Programming forums, part of the General Programming Boards category; /* I'm new in programming world and facing a problem..when i compile the given code in "turbo c++ 4.5" its ...

  1. #1
    Registered User Rakesh o_O's Avatar
    Join Date
    Jun 2012
    Location
    India
    Posts
    9

    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.
    */

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

  2. #2
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    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.
    memcpy, Rakesh o_O and Salem like this.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    "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.
    Rakesh o_O likes this.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,246
    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%.

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, 02: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-16-2003, 11:55 PM
  5. make windows shutdown
    By GravtyKlz in forum Windows Programming
    Replies: 1
    Last Post: 03-12-2003, 10:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21