Thread: hide Character

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    29

    hide Character

    HI.

    Does somebody know how to put a char # in every character we type.
    I think that it is with Systems Calls.

    Example: The program gives me a random character.
    Then i have to type the same character, but it haves to appears
    ´#´.


    Code:
    #include <stdio.h>
    
    /**************************************
    função generateChar()
    retorna uma letra minúscula aleatória
    **************************************/
    char x;
    
    char generateChar() {
      static char first = 1;
      if (first) {
        first = 0;
        srandom(time(NULL));
      }
      x = random()%26+'a';
      return x;
    }
    
    int main(int argc, char *argv[]) {
    
      char caracter;
    
      if(argc < 2) {                                             //Verifica o numero de argumentos passados
        printf("FALTAM ARGUMENTOS\n");
        exit(1);
      }
      int valor = atoi(argv[1]);                                 // transforma o argv[1] em inteiro
      int i;
     
      for(i = 0;i<valor;i++) {                                   // Ciclo que imprime o caracter aleatorio o numero de vezes passado a argv[1]
    
      printf("%c\n",generateChar());
    
      do {
        scanf(" %c",&caracter);                                  // Le o caracter dado pelo utlizador
        if(caracter != x) {                                      // Verifica se é igual ao aleatorio
        printf("TENTE DE NOVO\n");
      }
      }
      while(caracter != x);                                      // enquanto o caracter introduzido fôr diferente do aleatorio continua a pedir
      }
    
      printf("Letra\t\tTempo de Resposta\t\tInstante da resposta\n");
      printf("%c\t\t\t\t\t\t%s%s\n", x, __DATE__":",__TIME__);
        
    }

    If i insert ´a´, it haves to appear ´#´, but must read ´a´, the output of the letters must be always a '#' like a password but the program must save the letter and not the '#'.

    Thanks

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    Quote Originally Posted by Calavera
    HI.

    Does somebody know how to put a char # in every character we type.
    I think that it is with Systems Calls.

    Example: The program gives me a random character.
    Then i have to type the same character, but it haves to appears
    ´#´.


    Code:
    #include <stdio.h>
    
    /**************************************
    função generateChar()
    retorna uma letra minúscula aleatória
    **************************************/
    char x;
    
    char generateChar() {
      static char first = 1;
      if (first) {
        first = 0;
        srandom(time(NULL));
      }
      x = random()%26+'a';
      return x;
    }
    
    int main(int argc, char *argv[]) {
    
      char caracter;
    
      if(argc < 2) {                                             //Verifica o numero de argumentos passados
        printf("FALTAM ARGUMENTOS\n");
        exit(1);
      }
      int valor = atoi(argv[1]);                                 // transforma o argv[1] em inteiro
      int i;
     
      for(i = 0;i<valor;i++) {                                   // Ciclo que imprime o caracter aleatorio o numero de vezes passado a argv[1]
    
      printf("%c\n",generateChar());
    
      do {
        scanf(" %c",&caracter);                                  // Le o caracter dado pelo utlizador
        if(caracter != x) {                                      // Verifica se é igual ao aleatorio
        printf("TENTE DE NOVO\n");
      }
      }
      while(caracter != x);                                      // enquanto o caracter introduzido fôr diferente do aleatorio continua a pedir
      }
    
      printf("Letra\t\tTempo de Resposta\t\tInstante da resposta\n");
      printf("%c\t\t\t\t\t\t%s%s\n", x, __DATE__":",__TIME__);
        
    }

    If i insert ´a´, it haves to appear ´#´, but must read ´a´, the output of the letters must be always a '#' like a password but the program must save the letter and not the '#'.

    Thanks

    can u please translate your comments into proper english??

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    can u please translate your comments into proper english??
    Why? C is C. You should be able to understand the code for what it is. Sure, not all C is nice and clean to read, but it's still C. Why did you quote the entire thing just to post one wanna-be sentence?

    To answer the origional poster, there is no standard way to do this. It is dependant on your OS and compiler. Consider perusing some of these forum search results.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You also need to figure out how to drive your compiler in 'C' mode rather than C++ mode.

    > If i insert ´a´, it haves to appear ´#´, but must read ´a´, the output of the letters must be always a '#' like a password
    There is no way to do this without knowing your operating system and compiler.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    29
    My operating system is Linux.
    The gnu compiler.

    Code:
    #include <stdio.h>
    
    /**************************************
    function generateChar()
    returns a lower case character
    **************************************/
    char x;
    
    char generateChar() {
      static char first = 1;
      if (first) {
        first = 0;
        srandom(time(NULL));
      }
      x = random()%26+'a';
      return x;
    }
    
    int main(int argc, char *argv[]) {
    
      char caracter;
    
      if(argc < 2) {                                             //Verify the number of arguments
        printf("Lack of arguments\n");
        exit(1);
      }
      int valor = atoi(argv[1]);                                 // transforms argv[1] in integer
      int i;
     
      for(i = 0;i<valor;i++) {                                   // Cicle that prints the random character the number of times of argv[1]
    
      printf("%c\n",generateChar());
    
      do {
        scanf(" %c",&caracter);                                  // Reads the character the user wrigths
        if(caracter != x) {                                      // Verify if the character of the user is equal to the random character
        printf("TRY AGAIN\n");
      }
      }
      while(caracter != x);                                      // Keeps asking to type character until is not equal to the random character
      }
    
      printf("Character\t\tReaction Time\t\tDATE and TIME\n");
      printf("%c\t\t\t\t\t\t%s%s\n", x, __DATE__":",__TIME__);
        
    }

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You'll likely want something like the curses library, which allows for terminal and input manipulation, snazzy ansi color, and the like. Google will likely have a ton of info on it.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    29
    I have read the FAQ, and i have already understand it.
    Thanks aniway.

  8. #8
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    Quote Originally Posted by Calavera
    I have read the FAQ, and i have already understand it.
    Thanks aniway.
    what u mean is that u want to accept a word or something of that sort,and u also want to display it on the screen but want the output to be in #'s
    e.g.
    if u accept the word as ping,u want it to be displayed as ####??
    is that what u want to do??

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Calavera
    I have read the FAQ, and i have already understand it.
    Thanks aniway.
    What? I suggested you use the curses library, which is, a library for unix systems (typically) which allows for changing how the cursor works and color and screen manipulation. What does that have to do with the FAQ? *throws up hands and walks away*

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character literals incorrectly interpreted
    By DL1 in forum C Programming
    Replies: 11
    Last Post: 04-05-2009, 05:35 PM
  2. wide character (unicode) and multi-byte character
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 05-05-2007, 12:46 AM
  3. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  4. Character handling help
    By vandalay in forum C Programming
    Replies: 18
    Last Post: 03-29-2004, 05:32 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM