Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 25th, 2005, 7:57 PM   #1
UnKnown X
Hobbyist Programmer
 
UnKnown X's Avatar
 
Join Date: Dec 2005
Location: Sandvika, Norway
Posts: 114
Rep Power: 0 UnKnown X is an unknown quantity at this point
Send a message via MSN to UnKnown X
[C++] Pseudo-random "password" generator

I got bored and made a simple programme that generates a pseudo-random string containing lower and uppercase letters and digits.

Surprisingly enough, I actually have use for this program... Odd.

#include <iostream>
#include <time.h>

int main(void){
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
    unsigned int i,j;

    start:
    std::cout<<"Enter amount of chars (max 16386): ";
    std::cin>>j;
    if (j>16386)
    {
        std::cout<<"error: too much\n";
        goto start;
    }
    for (i=0;i<1;++i)
    {
        unsigned int a[j];
        for (i=0;i<j;++i)
        {
            while (!(((a[i]=rand())>='0'&&a[i]<='9')||(a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z')))
                ;
            printf("%c",a);
        }
    }
    printf("\n");
    std::cout << "Press enter to continue...";
    std::cin.sync();
    std::cin.get();
    std::cout << std::endl;
    goto start;
}


I know, I know. I used gotos... but I sort of like them!


Edit: Also, I have no idea why I put a redundant for loop there.

Edit again: Oh, right! To make a new array every time it loops! Though I could've just reset it... Oh well
UnKnown X is offline   Reply With Quote
Old Dec 25th, 2005, 9:32 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Agh, what is that while line! That could theoretically pop it into a almost infinite loop ... a kill on processing time. The rest of the code looks pretty dirty, and GOTOs are evil, but i congratulate you on a working program since that was probably your primary goal at your skill level. Good job, but LOTS to work on
__________________

tempest is offline   Reply With Quote
Old Dec 25th, 2005, 9:35 PM   #3
UnKnown X
Hobbyist Programmer
 
UnKnown X's Avatar
 
Join Date: Dec 2005
Location: Sandvika, Norway
Posts: 114
Rep Power: 0 UnKnown X is an unknown quantity at this point
Send a message via MSN to UnKnown X
I guess I like working quickly and dirty

I'll get back to it some time though.



Edit: In that while loop, the forum decided to format my code's [ i ] as vBcode and instead of putting the [ i ] there, it put the code that followed in Italic, so it's always evaluating a[0]. I didn't notice what the problem was at the time, so I just added a [/ i ] at the end of the code block. Oh, well.
UnKnown X is offline   Reply With Quote
Old Dec 25th, 2005, 9:56 PM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
add a [i] to the top of the code block next time and it'll be set, it seems like it only processes the first one since doing the rest would be redundant (although the entire prospect of BBCode in the [ code ] tag is stupid in the first place...)
__________________

tempest is offline   Reply With Quote
Old Dec 25th, 2005, 10:51 PM   #5
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
Originally Posted by tempest
although the entire prospect of BBCode in the [ code ] tag is stupid in the first place...
Not always. Sometimes you want to highlight some code in the code tags by changing its color or making it bold.

But a[i] is fairly common in C code as well.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Dec 26th, 2005, 7:49 AM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
well, i mean for code it's important to give the user the ability to turn the feature on and off atleast ... or even if they didn't want to do that, they could limit the tags possible to use to like [ highlight ] or something....
__________________

tempest is offline   Reply With Quote
Old Dec 26th, 2005, 8:01 AM   #7
UnKnown X
Hobbyist Programmer
 
UnKnown X's Avatar
 
Join Date: Dec 2005
Location: Sandvika, Norway
Posts: 114
Rep Power: 0 UnKnown X is an unknown quantity at this point
Send a message via MSN to UnKnown X
Yesh. Or implement something like:
tags Syntax (Toggle Plain Text)
  1. Code here
UnKnown X is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:30 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC