Arghhhhhhhhh why does this not terminate?

This is a discussion on Arghhhhhhhhh why does this not terminate? within the C++ Programming forums, part of the General Programming Boards category; ok simple password generator... and i dont get why my program will not terminate... it keeps running forever Code: #include ...

  1. #1
    Unregistered
    Guest

    Arghhhhhhhhh why does this not terminate?

    ok simple password generator... and i dont get why my program will not terminate... it keeps running forever

    Code:
    #include <stdlib.h> 
    #include <stdio.h> 
    #include <time.h>   
    #include <iostream.h>
    #include <iostream.h>
    #include <fstream.h>
    
    int main()
    {
    	char *chars[93] = 	
    
    	{
    "A","B","C","D",
    "E","F","G","H",
    "I","J","K","L",
    "M","N","O","P",
    "Q","R","S","T",
    "U","V","W","X",
    "Y","Z","1","2",
    "3","4","5","6",
    "7","8","9","0",
    "a","b","c","d",
    "e","f","g","h",
    "i","j","k","l",
    "m","n","o","p",
    "q","r","s","t",
    "u","v","w","x",
    "y","z","~","`",
    "!","@","#","$",
    "%","^","&","*",
    "(",")","-","_",
    "=","+","[","]",
    "{","}",";",":",
    "|","?",">","<",
    ".",",","'"," ",
    	0
    };
    
    {
    	int x;
    	int numofpass;
    	
    	srand(time(NULL));
    	cout<<"Password's length to be generated"<<endl;
    	cin>>x;
    	cout<<"Number of Passwords to generate"<<endl;
    	cin>>numofpass;
    	ofstream a_file("Passwords.txt");
    	
    	int count = 0;
    	while (count<numofpass)
    	{
    	int num = 0;
    	
    	while (num<x)
    	{
    	num++;
    	int matrixinput = rand() % 92;
    	a_file<<chars[matrixinput];
    	}
    	cout<<""<<endl;
    	}
    	a_file.close();
    }
    return 0;
    }

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    count is never incremented.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Your not incrementing count maybe

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    9
    while (count<numofpass)
    {
    int num = 0;
    while (num<x)
    {
    num++;
    int matrixinput = rand() % 92;
    a_file<<chars[matrixinput];
    }
    cout<<""<<endl;
    count++; // try adding this line...
    }
    a_file.close();
    }

    Well, you're stuck inside the while(count<numofpass) loop because count stays zero and if you put a number greater than or equal to 0 in for numofpass it stays in there, add that count++ line and count will increment 1 every time it goes through creating a random password until count is greater than numofpass. Hope that helps.

  5. #5
    Unregistered
    Guest
    damn im ........ed now... lol i guess you shouldnt code when your distracted lol

    i feel stupid lol such a dumb mistake

  6. #6
    Unregistered
    Guest
    while we are at it how is my code ethiquette/ programming style? any suggestions?

  7. #7
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    You are missing the two most important thing: Comments and indentations.
    Yoshi

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    This forum doesn't indent right if the text isn't in a code box.

  9. #9
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    I feel kinda dumb askin this, but why are all those chars in double quotes instead of single quotes?

  10. #10
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    They are pointers
    Yoshi

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    revision

    Try this for better code:

    Code:
    PHP Code:
    #include <cstdlib>  #include <ctime>    #include <iostream> #include <fstream> using namespace std//pass filename to function instead of always using static name void gen_passwords(char filename) {          /*if i were you i'd take away the * before chars and make all the letters in single quotes also i'd avoid using some of the characters you have in this array in a password */          const int numChars 93//allows for changes in array size to be made universally          char *pwchars[numChars] = { "A","B","C","D", "E","F","G","H", "I","J","K","L", "M","N","O","P", "Q","R","S","T", "U","V","W","X", "Y","Z","1","2", "3","4","5","6", "7","8","9","0", "a","b","c","d", "e","f","g","h", "i","j","k","l", "m","n","o","p", "q","r","s","t", "u","v","w","x", "y","z","~","`", "!","@","#","$", "%","^","&","*", "(",")","-","_", "=","+","[","]", "{","}",";",":", "|","?",">","<", ".",",","'"," ",};       int length,numofpass//more meaningful identitfier       ofstream pwfile(filename); //i moved this up because usually you should try to keep variable declarations together            srand(time(NULL)); //initialize random number generator       cout<<"Password's length to be generated"<<endl;       cin>>length;       cout<<"Number of Passwords to generate"<<endl;       cin>>numofpass;       for(int i 0numofpassi++) //for loop over while       {             for(int j 0lengthj++) //once again for over while             {                      pwfile<< pwchars[(rand() % numChars)]; //do random inside []'s to avoid wasting a variable             }             cout<<""<<endl//what is reason for this line?       }       pwfile.close(); } 

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. terminate() function
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2009, 10:37 AM
  2. Terminate Boost::Thread
    By CornyKorn21 in forum C++ Programming
    Replies: 3
    Last Post: 06-03-2008, 01:19 PM
  3. how to terminate a target thread
    By swaugh in forum C++ Programming
    Replies: 2
    Last Post: 01-24-2005, 11:13 AM
  4. How to terminate a process
    By BianConiglio in forum Windows Programming
    Replies: 12
    Last Post: 04-05-2004, 04:53 PM

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