Thread: i have some questions...?

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    11

    Question i have some questions...?

    the story began when i wanted to create password program(insertion password)
    my thought was that insert char by char and transforms any char into star symbol(*) of course after a short time of appearing
    to understand what i talk about it this is the final format of the program which i create it is:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include<stdbool.h>
    #include<windows.h>
    #include<time.h>
    #include<conio.h>
    
    COORD coord={0,0};
    void gotoxy(int x,int y);
    
    int main(void)
    {
        char password[20];
        int i=0,j=0;
        clock_t cpu_start=0L;
    
    
    
        while(1)
        {
    
            password[i]=getch();
            if(password[i]=='\r')/// new_line 
                break;
            cpu_start=clock();
            gotoxy(j,0);
            putchar(password[i]);
            for(;clock()-cpu_start<CLOCKS_PER_SEC;);
            gotoxy(j,0);
            putchar('*');
    
            i++;
            j++;
    
    
        }
        password[i]='\0';
        printf("\nthe password which you entered is; %s",password);
    
    
      return 0;
    }
    ///code to move the cursor in  the position we want it
    void gotoxy(int x,int y)
    {
        coord.X=x;
        coord.Y=y;
    
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
    }
    so ,before reaching this (program above )
    i use this function getchar()instead of getch()
    but the result was not what i want and it was that: you have to enter newline char(press enter) to any inserted char and it's impossible to do that and it's impractical,even i use getc() function.
    after i did the debugging process
    my conclusion was that ; getchar () function stores the character which you entered in buffer memory then from buffer memory the char transmits into the variable,but the getch() function stores the char in variable immediately,and getch() equivalent to getche(),and getchar() equivalent getc()

    1-is my conclusion correct or no?.
    2-problem with getch() is that you can't delete the char after you write it because it stores the key of delete as a char,is there solution?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by sweezy
    my conclusion was that ; getchar () function stores the character which you entered in buffer memory then from buffer memory the char transmits into the variable,but the getch() function stores the char in variable immediately
    Yes.

    Quote Originally Posted by sweezy
    getch() equivalent to getche(),and getchar() equivalent getc()
    Not exactly: getch and getche differs in that getche also echos. Keep in mind that both (and conio.h in general) are non-standard. getchar and getc differ in that getc can be used with input streams other than standard input. getc would be closer to fgetc in that respect.

    Quote Originally Posted by sweezy
    problem with getch() is that you can't delete the char after you write it because it stores the key of delete as a char,is there solution?
    Detect that delete was entered, and hence remove the previous character from the string instead of storing the delete character in the string.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    11
    laserlight plz your fcb account
    Last edited by sweezy; 12-14-2015 at 08:21 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Huh?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Oct 2015
    Posts
    11
    laserlight fcb=facebook... plz to to communicate
    Last edited by sweezy; 12-14-2015 at 08:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IDE questions
    By SterlingM in forum C++ Programming
    Replies: 1
    Last Post: 10-19-2009, 05:13 AM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. 5 questions
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2007, 11:32 PM
  4. several questions
    By PHP in forum C++ Programming
    Replies: 3
    Last Post: 12-19-2002, 10:25 PM
  5. more questions!!
    By Yoshi in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2002, 09:06 AM

Tags for this Thread