string-keygen type app

This is a discussion on string-keygen type app within the C++ Programming forums, part of the General Programming Boards category; hi, i want to make a kind of keygen using strings.. this app accepts name then never comes back. Code: ...

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

    string-keygen type app

    hi, i want to make a kind of keygen using strings..
    this app accepts name then never comes back.
    Code:
    #include <iostream.h>
    #include <string.h>
    
    void main(void)
    {
    	char string[50];
    	char retstring[50];
    	int length,x;
    
    	cout<<"Enter your name: ";
    	cin.getline(string,50,'\n');
    	length=strlen(string);
    
    	for (x=0;x=length;x++)
    	{
    		string[x]=string[x]+1;
    	}
    
    	cout<<"\nYour password is: "<<string;
    }
    whats up with that?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>for (x=0;x=length;x++)
    Are you sure you want assignment there?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    29
    how do you mean mate?

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    for (x=0;x=length;x++)

    The equal sign is an assignmwnt operator; it is used to set a variable or array to a value.

    You want the double equal sign, which tests if the two are equal.

    for (x=0; x==length; x++)

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>it is used to set a variable or array to a value.
    I disagree... If you try setting an array using the equals sign, you'll just be changing the address it points to, which is pointless (haha pun... *cough cough*), and besides which it will most likely give you a compiler error (MSVC does, haven't tested any others). The only time you can use = to set an array is at initialization, using curly braces to indicate that you're specifying a list of elements.

    As a side note, I prefer to use ++x instead of x++ when it can be used interchangeably, because it is *potentially* faster, by 1/9999 ms

    Aside from that, I agree with everything that's been said.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >If you try setting an array using the equals sign, you'll just be changing the address it points to
    Well if the array was actually declared as an array, an assignment to it is illegal because an array is only converted to a pointer to the first element in an expression (excluding sizeof and address-of (&) being performed on the array), a function argument or a subscript operation. An array name is not a modifiable lvalue, thus cannot be assigned to.

    If the array is simulated dynamically with a pointer or points to an array declared as an array then what you said is true.

    >it will most likely give you a compiler error
    It definitely will since it is a constraint violation.

    >because it is *potentially* faster
    Fair enough. Though with built-in types you should get a better compiler if ++i is noticeably faster than i++ in all but the most pedantic of tests that would never reasonably arise in any real code.

    >by 1/9999 ms
    And how many times would that statement have to be iterated over before the speed difference actually makes a difference?
    My best code is written with the delete key.

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>an array is only converted to a pointer to the first element in an expression (excluding sizeof and address-of (&) being performed on the array), a function argument or a subscript operation.

    Ah wow, never knew that... all my books always just said that an array is a pointer

    >>And how many times would that statement have to be iterated over before the speed difference actually makes a difference?

    Er... if you had a [(really)e99]^20 heavy-duty server program?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    1

    Smile for statements

    Hi,

    After all the posts that I bet didn't really help you, here is why it didn't work.

    The for-statement works like this

    for (<counter var definition>;<loop condition>;<increment/decrement>)


    The <loop condition> expression must be FALSE in order for the for loop to exit, or in other words, the for-loop will continue until the condition is FALSE.

    In your code, you did an assignment, which when evaluated, is always (for the purposes of this discussion) TRUE. So, you have created yourself a nice endless loop.

    What you want to do, based on what you said and what I think your goal is, is to change that line to

    (int i=0; i < length ; i++)

    or, in pseudocode,

    "start with i equal to zero, and while it's less than length, do what's in brackets below, then increase i, and come back here."

    I hope that helps a bit more than the other stuff posted above here, which may all be true, but I think is not very helpful to you.

    Good luck!


  9. #9
    Registered User
    Join Date
    Feb 2004
    Posts
    29
    nice work gice. 100x thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  4. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  5. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM

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