Compartilhar via


_ungetch, _ungetwch, _ungetch_nolock, _ungetwch_nolock

Envia novamente o último caractere ler a partir do console.

int _ungetch(
   int c 
);
wint_t _ungetwch(
   wint_t c 
);
int _ungetch_nolock(
   int c 
);
wint_t _ungetwch_nolock(
   wint_t c 
);

Parâmetros

  • c
    Caractere ser transferido.

Valor de retorno

Ambas as funções retornam o caractere c Se for bem-sucedido. If there is an error, _ungetch returns a value of EOF and _ungetwchreturnsWEOF.

Comentários

These functions push the character c back to the console, causing c to be the next character read by _getch or _getche (or_getwch or_getwche)._ungetch e _ungetwch falha se eles são chamados de mais de uma vez antes da próxima leitura. The c argumento pode não estar EOF (ou WEOF).

As versões com o _nolock sufixo são idênticas exceto que eles não estão protegidos contra interferência por outros threads. Eles podem ser mais rápidos, pois eles não aumentam a sobrecarga de bloqueio de outros segmentos.Utilizar essas funções em contextos de thread-safe, sistema autônomo aplicativos single-threaded ou onde o escopo de chamada já manipula o thread isolamento.

Mapeamentos de rotina de texto genérica

Rotina TCHAR.H

_UNICODE & _MBCS não definido

_MBCS definido

_UNICODE definido

_ungettch

_ungetch

_ungetch

_ungetwch

_ungettch_nolock

_ungetch_nolock

_ungetch_nolock

_ungetwch_nolock

Requisitos

Rotina

Cabeçalho necessário

_ungetch, _ungetch_nolock

<conio.h>

_ungetwch, _ungetwch_nolock

<conio.h> ou <wchar.h>

Para obter informações adicionais compatibilidade, consulte Compatibilidade na introdução.

Exemplo

// crt_ungetch.c
// compile with: /c
// In this program, a white-space delimited 
// token is read from the keyboard. When the program 
// encounters a delimiter, it uses _ungetch to replace 
// the character in the keyboard buffer.
//

#include <conio.h>
#include <ctype.h>
#include <stdio.h>

int main( void )
{
   char buffer[100];
   int count = 0;
   int ch;

   ch = _getche();
   while( isspace( ch ) )      // Skip preceding white space.
      ch = _getche();
   while( count < 99 )         // Gather token.
   {
      if( isspace( ch ) )      // End of token.
         break;
      buffer[count++] = (char)ch;
      ch = _getche();
   }
   _ungetch( ch );            // Put back delimiter.
   buffer[count] = '\0';      // Null terminate the token.
   printf( "\ntoken = %s\n", buffer );
}

White

token = White

Consulte também

Referência

Console e porta de E/s

_cscanf, _cscanf_l, _cwscanf, _cwscanf_l

_getch, _getwch