Thread: warning C4996: 'getch': The POSIX name for this item is deprecated.

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    14

    warning C4996: 'getch': The POSIX name for this item is deprecated.

    Hello
    I have no idea what does this error message means.
    the error message is related to the switch statement in function paintGame.
    It is not the complete code I just put the codes that might help to understand it.

    any suggestion would be appreciated.
    Thanks





    Code:
    #define STORAGE ('+') 	    //store area
    int main()
    {
    	void paintGame( char g[][ SIZEX+1], string& mess,string& name,int a[], int dx,int dy);
            char grid[ SIZEY+1][ SIZEX+1];	      //grid for display
    	string message = "LET'S START...";
    	int ap[2];
    	int dx( 0), dy( 0);
    
            paintGame( grid, message,name,ap, dx, dy);	//display game info, modified grid & messages
    }
    Code:
    void paintGame(char gd[][ SIZEX+1], string& mess, string& name,int a[], int dx,int dy)
    { //display game title, messages, maze, mouse & apples on screen
    	void paintGrid( const char g[][ SIZEX+1]);
    	int calculateStoringScore();
    	switch (gd[a[0]-dy][a[1]-dx])
    	{
    	case STORAGE:
    		Gotoxy(40, 10);
    		cout << "NUMBER OF APPLES IN STORE:" << calculateStoringScore();
    		break;
    	}
    }

    Code:
    int calculateStoringScore()
    {
    		int count=0;
    		for (count=0;count<6;count++)
    		{
    		}
    		return count;
    }

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I can't see how it's realted to the switch statement. You don't call getch() there.

    The problem is that getch() is a non-standard function, and MS compilers have traditionally offered those under two names - once simply as they are, once with a leading underscore (_getch()), as befits a standard library extension. Apparently, the new compilers warn that the versions without the leading underscore (misleadingly called "POSIX names" - that's because the same warning also applies to the POSIX compatibility functions the compiler offers) are deprecated, i.e. they might go away in a future version of the compiler.

    The solution is to use _getch() instead of getch(), or better yet, use something else entirely.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    14

    Unhappy

    yes.you were right. I get rid of that error but it still doesn't compile and does not show any error or warning, only thing is the yellow arrow which points to the switch statement.
    I don't know what to do

    It says "Unhandled exception at 0x00413612 in Assignment2.exe: 0xC0000005: Access violation reading location 0xccdfcb00." break or continue!!!!!
    Last edited by jojo13; 04-12-2008 at 10:22 AM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That's not a compile error, that's a runtime error. And the problem is that the members of ap are uninitialized, so a[0]-dy and a[1]-dx are both pretty much random values, so the whole array access goes to ... some not very nice place.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    14
    Thanks.
    but do you have any idea of how to solve this problem??!!
    It is about couple of weeks that I am working on this but nothing
    by the way thanks for your respond
    Last edited by jojo13; 04-12-2008 at 12:38 PM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Initialize the values in ap.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM