Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with toupper()

Status
Not open for further replies.

jgavin

Programmer
Jun 21, 2002
2
0
0
CA
When I compile my program, the compiler tells me that toupper() is an undeclaired variable. The library for this function has been included, so I'm wondering if I'm using it wrong or if the library may be corrupt?

This is how I'm using it:
XXX = toupper(getche());
 
I believe you actually *are* having a problem with getche(). If you're using Microsoft Visual C++, you need to use this function instead:
Code:
_getch() // with the preceding underbar character
Here's the MSDN example:
Code:
#include <conio.h>
#include <ctype.h>

void main( void )
{
   int ch;

   _cputs( &quot;Type 'Y' when finished typing keys: &quot; );
   do
   {
      ch = _getch();
      ch = toupper( ch );
   } while( ch != 'Y' );

   _putch( ch );
   _putch( '\r' );    /* Carriage return */
   _putch( '\n' );    /* Line feed       */
}
 
... or for your example, use:
Code:
 _getche() // again, with the preceding underbar character
 
Well that certainly put some light on the problem, even though my final solution was to avoid using getche() altogether. I had previously tried to use toupper() in this way:
cin >> ch;
toupper(ch);//without success

but what did work was:
cin >> ch;
ch = toupper(ch);//success

Thankyou for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top