× Register Login What's New! Contact us
Results 1 to 8 of 8 visibility 2193

C++

  1. #1
    Cabdullahi's Avatar Full Member
    brightness_1
    IB Oldskool
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Sep 2006
    Location
    London...previously coventry
    Gender
    Male
    Religion
    Islam
    Posts
    5,610
    Threads
    151
    Rep Power
    141
    Rep Ratio
    94
    Likes Ratio
    7

    C++

    Report bad ads?

    Anybody here good at c++...ive designed a password function but its kinda useless....it doesnt compare it with the a set password....basically im kinda wack at this maybe some1 could help me

    here's the code

    // hndfh.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"


    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }

    // 00000.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    #include <windows.h>

    using namespace std;

    int main ()
    {
    cout << "Enter you password: (max 4 characters)" << endl;
    // password (char array, doesn't work as string)
    char password[25];

    int i = 0; // used to index the current character being read
    while (true) // infinite loop, broken by pressing return
    {
    password[i] = getch(); // get the current character
    cout << "*"; // output a star (can be replaced with a different character)

    if (GetAsyncKeyState(VK_RETURN)) // if return has been pressed
    break; // break from the loop

    i++; // increment our index
    }

    // now fill the rest of the array with '\0' (NULL) character
    for (i; i < strlen(password); i++)
    password[i] = '\0';

    // output the password (just for testing)
    cout << endl << "Welcome Ahmed Ali";

    // end of the program
    cout << endl << "Press any key to continue . . .";
    getch ();
    }
    chat Quote

  2. Report bad ads?
  3. #2
    AabiruSabeel's Avatar Administrator
    brightness_1
    عـــابر سبيـــل
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Mar 2006
    Gender
    Male
    Religion
    Islam
    Posts
    9,175
    Threads
    376
    Rep Power
    183
    Rep Ratio
    133
    Likes Ratio
    45

    Re: C++



    You are not comparing it with a stored password. And you are not displaying the pwd where you say:
    // output the password (just for testing)
    cout << endl << "Welcome Ahmed Ali";
    If you are testing it, then there should be a <<password also in that statement.

    Another point that I noticed:
    // now fill the rest of the array with '\0' (NULL) character
    for (i; i < strlen(password); i++)
    password[i] = '\0';
    There is no need for the loop here, since you are not changing the value of the index i after entering the password in the previous loop. And since it was counting the no. of chars entered, it will be pointing at the end of the password already. You can simply write password[i] = '\0'; and it will close the string. Try it.

    Don't you think this thread should be in the Educational Issues section?

    Its late night here. If there are other queries, I will try to check tomorrow inshaAllah.

    chat Quote

  4. #3
    Forced_In's Avatar Full Member
    brightness_1
    Full Member
    star_rate star_rate star_rate
    Join Date
    Apr 2009
    Religion
    Unspecified
    Posts
    88
    Threads
    5
    Rep Power
    95
    Rep Ratio
    30
    Likes Ratio
    0

    Re: C++

    format_quote Originally Posted by Abdullahii View Post
    Anybody here good at c++...ive designed a password function but its kinda useless....it doesnt compare it with the a set password....basically im kinda wack at this maybe some1 could help me

    here's the code

    // hndfh.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"


    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }

    // 00000.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    #include <windows.h>

    using namespace std;

    int main ()
    {
    cout << "Enter you password: (max 4 characters)" << endl;
    // password (char array, doesn't work as string)
    char password[25];

    int i = 0; // used to index the current character being read
    while (true) // infinite loop, broken by pressing return
    {
    password[i] = getch(); // get the current character
    cout << "*"; // output a star (can be replaced with a different character)

    if (GetAsyncKeyState(VK_RETURN)) // if return has been pressed
    break; // break from the loop

    i++; // increment our index
    }

    // now fill the rest of the array with '\0' (NULL) character
    for (i; i < strlen(password); i++)
    password[i] = '\0';

    // output the password (just for testing)
    cout << endl << "Welcome Ahmed Ali";

    // end of the program
    cout << endl << "Press any key to continue . . .";
    getch ();
    }
    assalam

    Have you considered joining a usenet group like "comp.lang.c++" ? I think you will learn a lot there abot cpp.

    wassalam
    chat Quote

  5. #4
    Cabdullahi's Avatar Full Member
    brightness_1
    IB Oldskool
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Sep 2006
    Location
    London...previously coventry
    Gender
    Male
    Religion
    Islam
    Posts
    5,610
    Threads
    151
    Rep Power
    141
    Rep Ratio
    94
    Likes Ratio
    7

    Re: C++

    haha the starting thread was a big joke ...i fooled you guys this is my password function

    // ff.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"


    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }

    #include <string>
    #include <iostream>
    using std::string;
    using std::cin;
    using std::cout;

    int main(){
    string a;
    cin>>a;
    if(a == "1234"){

    cout<<"Welcom Mr Ahmed Ali \n";
    }
    else if (a != "1234"){
    cout << "incorrect password, please try again.";
    }
    system("PAUSE");
    return 0;
    }
    chat Quote

  6. Report bad ads?
  7. #5
    convert's Avatar Full Member
    brightness_1
    Full Member
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Apr 2009
    Religion
    Unspecified
    Posts
    440
    Threads
    5
    Rep Power
    96
    Rep Ratio
    81
    Likes Ratio
    1

    Re: C++

    Should probably be using hashes for password stuff.
    chat Quote

  8. #6
    AabiruSabeel's Avatar Administrator
    brightness_1
    عـــابر سبيـــل
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Mar 2006
    Gender
    Male
    Religion
    Islam
    Posts
    9,175
    Threads
    376
    Rep Power
    183
    Rep Ratio
    133
    Likes Ratio
    45

    Re: C++



    Both are two different methods of coding. In the first one, you are simply entering the pwd and then displaying it. If you want to check it with a stored pwd, then you will have to learn file handling as well.

    In your second program, you have hardcoded the password, and you are not using asterisk to mask it while entering. Hardcoded pwds cannot be changed, therefore not user-friendly. Its better to use hashes, and store the pwds in a file, and use it for login.

    what does the strlen function return?
    strlen() returns the length of the string in int. You will have to include string.h header file for it.
    chat Quote

  9. #7
    AabiruSabeel's Avatar Administrator
    brightness_1
    عـــابر سبيـــل
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Mar 2006
    Gender
    Male
    Religion
    Islam
    Posts
    9,175
    Threads
    376
    Rep Power
    183
    Rep Ratio
    133
    Likes Ratio
    45

    Re: C++

    ^yes it takes a string, and returns the number of characters in it.
    The declaration syntax in string.h is:
    Code:
    size_t strlen(const char *s);
    chat Quote

  10. #8
    Yanal's Avatar
    brightness_1
    Student of knowledge
    star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate star_rate
    Join Date
    Feb 2007
    Gender
    Male
    Religion
    Islam
    Posts
    6,055
    Threads
    160
    Rep Power
    116
    Rep Ratio
    8
    Likes Ratio
    1

    Re: C++

    I thought you needed help with grades because you got C+,but it's not about that. All this computer stuff is hard....
    chat Quote


  11. Hide
Hey there! C++ Looks like you're enjoying the discussion, but you're not signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. And you can like posts and share your thoughts. C++
Sign Up

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
create