Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. char+char issues

char+char issues

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gamefreak2291
    wrote on last edited by
    #1

    I'm trying to get my program to print out an asterisk when then user is typing in his/her password. I've gotten this part to work, however. for debugging issues I'm also trying to make the program print the password at the end. It's currently only outputting the last letter typed in as if its the password. So, how can I make the program output the entire actual password. Here is my code: #include #include #include using namespace std; char password1; char password2; char password3; int x=1; int main() { do{ cout << "Enter a test password: " ; do{ password1=getch(); if((password1>=65) && (password1<=122)){cout << "*"; password2=password1; password3=password2+password1;} else{cout << "";} }while(password1!=13); cout << "\nYour password is " << password3; Sleep(2000); system("cls"); }while(x=1); return 0; } password2 and 3 were adding in when i was trying to get it to work.

    A 1 Reply Last reply
    0
    • G gamefreak2291

      I'm trying to get my program to print out an asterisk when then user is typing in his/her password. I've gotten this part to work, however. for debugging issues I'm also trying to make the program print the password at the end. It's currently only outputting the last letter typed in as if its the password. So, how can I make the program output the entire actual password. Here is my code: #include #include #include using namespace std; char password1; char password2; char password3; int x=1; int main() { do{ cout << "Enter a test password: " ; do{ password1=getch(); if((password1>=65) && (password1<=122)){cout << "*"; password2=password1; password3=password2+password1;} else{cout << "";} }while(password1!=13); cout << "\nYour password is " << password3; Sleep(2000); system("cls"); }while(x=1); return 0; } password2 and 3 were adding in when i was trying to get it to work.

      A Offline
      A Offline
      aks
      wrote on last edited by
      #2

      Did you check your program? 1. >> password1=getch(); - you are getting the KB i/p on password1. 2. >> password2=password1; - Assigning the same value to password2 3. >> password3=password2+password1; - concatenating the the same values to password3. Also you are concatinating 'char'( 1 byte) ie. the ascii value are added and will not be an expected value. Use password2 as a char array and use string functions to concatenate the password1 to password2.

      aks

      G 1 Reply Last reply
      0
      • A aks

        Did you check your program? 1. >> password1=getch(); - you are getting the KB i/p on password1. 2. >> password2=password1; - Assigning the same value to password2 3. >> password3=password2+password1; - concatenating the the same values to password3. Also you are concatinating 'char'( 1 byte) ie. the ascii value are added and will not be an expected value. Use password2 as a char array and use string functions to concatenate the password1 to password2.

        aks

        G Offline
        G Offline
        gamefreak2291
        wrote on last edited by
        #3

        reply, wouldnt allow me to do that, however, I fixed that issue around 30 minutes ago. I now have: #include #include #include using namespace std; char password1[25]; int x=1; int i=0; int main() { do{ cout << "Enter a test password: " ; for(i=0;i<25;i++){ password1[i]=getch(); if(((password1[i]>=65)&&(password1[i]<=90)) || ((password1[i]>=97)&&(password1[i]<=122)) || ((password1[i]>=48)&&(password1[i]<=57)) || ((password1[i]>=35)&&(password1[i]<=38)) || ((password1[i]>=40)&&(password1[i]<=42)) || ((password1[i]==33))||((password1[i]==64)) || ((password1[i]==94)) || ((password1[i]==32))){cout << "*"; i+1;} if(password1[i]==13){goto end;} else{cout << "";} } end: for (i; i < strlen(password1); i++){ password1[i] = '\0';} cout << "\nYour password is " << password1[0] << password1[1] << password1[2] << password1[3] << password1[4] << password1[5] << password1[6] << password1[7] << password1[8] << password1[9] << password1[10] << password1[11] << password1[12] << password1[13] << password1[14] << password1[15] << password1[16] << password1[17] << password1[18] << password1[19] << password1[20] << password1[21] << password1[22] << password1[23] << password1[24] << password1[25]; Sleep(2000); if(password1[i]=='password'){goto end1;} system("cls"); }while(x=1); end1: cout << "\nIT WORKS!"; getch(); return 0; } This works completely other than it doing the password check which im still looking into. feel free to help

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups