Asterisk Password

This is a discussion on Asterisk Password within the C Programming forums, part of the General Programming Boards category; I have success on doing password strings in asterisk in main(). Now, i would like to do it by using ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    13

    Asterisk Password

    I have success on doing password strings in asterisk in main().
    Now, i would like to do it by using function.

    How do I refer back to the function by creating a function block and passing the control to the caller of a function as above-mentioned problem? Does the C compiler will allocate more memory space than the conventional practice for this situation?

    Thank you.

  2. #2
    Registered User Inanna's Avatar
    Join Date
    May 2011
    Posts
    69
    Your question makes no sense at all.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Inanna View Post
    Your question makes no sense at all.
    Repeated for emphasis.

    More specifically: what do you think "function block" means (hint: whatever you think it is, it doesn't). Why would you want to pass control to the caller of a function? Either (a) you've finished the function, and control automatically returns from whence it came, or (b) you're not finished with the function, in which case returning is the very last thing you want to do. And any blather about memory space is probably at best misguided at this point (if optimizations need to be made, we're not there yet).

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    More to the point, it is already in a function block.

    If you have
    Code:
    int main ( ) {
      // your code here
    }
    You can simply rename it to being
    Code:
    int readAPassword ( ) {
      // your code here
    }
    
    int main ( ) {
      if ( readAPassword() ) {
        // you're in!
      }
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    The curses library should help. It should be available on Linux machines, you can download pdcurses for Windows machines. Try something like this.

    Code:
    #include <curses.h>
    
    int main() {
            initscr();
            int x, y;
            char passwd[25];
            noecho();
            printw("Enter your password: ");
            for (y = 0; (x = getch()) != 10 && y != 26; y++) {
                    /* loop will stop after 25 chars, or when
                     * the user hits enter */
                    passwd[y] = x;
                    printw("*");
            }
            passwd[y] = '\0';
            printw("\nYour password is: %s\n", passwd);                  
            getch();
            endwin();
            return 0;
    }
    Be sure to add -lcurses (or -lpdcurses if you're on Windows) to link the curses library when you compile. getch receives a keypress from stdin and returns an integer value, noecho ensures that whatever you type will not appear on the screen. And printw works just like printf. This might be a little overkill, and there's probably a better solution, but it's the first thing that came to my mind.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-07-2009, 09:35 AM
  2. Password Asterisk
    By $l4xklynx in forum C Programming
    Replies: 5
    Last Post: 10-30-2008, 03:08 PM
  3. masked with asterisk(*)?
    By ShadeS_07 in forum C Programming
    Replies: 32
    Last Post: 10-25-2008, 12:16 PM
  4. Display input(password) as asterisk(*)
    By seePLUSPLUSn00b in forum C++ Programming
    Replies: 5
    Last Post: 09-29-2008, 11:16 AM
  5. Diamond asterisk
    By P_of_Y in forum C++ Programming
    Replies: 33
    Last Post: 07-22-2006, 09:32 PM

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