CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2012
    Posts
    1

    How to run and improve this code - new to visual C++

    Hello,
    I forgot mine password to my folder but I do remember it partially I would like to generate possible passwords from set of characters and filter it with set of parameters.
    I found this code: ( downloaded visual C++ express but can't run it)
    I would like to ask for any help to run it . the link is ( http://www.cplusplus.com/articles/L8hv0pDG/) so it looks o.k.
    the code ( in case the link needs to be deleted :

    #include <iostream.h>
    #include <conio.h>
    #include <fstream.h>
    #include <math.h>
    int index_z=0,min,max;
    char alpha[10],temp;
    inline void intialize_values(int m) {
    for (int j=0;j<m;j++)
    { alpha[j]='a'; }
    }
    inline int increament(int l) {
    for (int a=l-1;a>=0;a--)
    {
    if (alpha[a]=='z' && min<=max) {
    alpha[a]='a';
    index_z++; }
    else {
    temp=alpha[a];
    temp++;
    alpha[a]=temp;
    index_z=0;
    break; }
    }
    if (index_z==l) {
    l++; }
    return l;
    }

    int main () {
    int len,val,last,check;
    double total=0E+0;
    ofstream outfile("random.txt");
    do {
    system("cls");
    cout << "min = ";
    cin >> min;
    cout << "max = ";
    cin >> max; } while(min>max || max==0);
    len=min;
    last=min;
    val=min;
    for (int i=min;i<=max;i++)
    {
    intialize_values(val);
    check=1;
    while (check==1) {
    for (int k=0;k<len;k++) {
    cout << alpha[k]; }
    cout << "\n";
    total++;
    len=increament(last);
    if (len>last) {
    last++;
    check=0;
    val++; }
    }
    }
    cout << "\n\n\n";
    cout << "Total Generated = " << total << endl;
    double ch=0E+0;
    for (int i=min;i<=max;i++) {
    ch+=pow(26,i); }
    if (total==ch)
    cout << "\n\n" << "Task Completed Successfully.";
    cout << "\n\n\n\t\t\tpress any key to exit...";
    getch();
    return 0;
    }



    Thanks in advance

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: How to run and improve this code - new to visual C++

    Quote Originally Posted by trubadur View Post
    Hello,
    I found this code: ( downloaded visual C++ express but can't run it)
    I would like to ask for any help to run it . the link is ( http://www.cplusplus.com/articles/L8hv0pDG/) so it looks o.k.
    the code ( in case the link needs to be deleted :
    Please use code tags when posting code. The code you posted is practically unreadable.

    For the sake of everyone reading your message:
    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <fstream.h>
    #include <math.h>
    int index_z=0,min,max;
    char alpha[10],temp;
    inline void intialize_values(int m) {
         for (int j=0;j<m;j++)
         { alpha[j]='a'; }
         }
    inline int increament(int l) {
         for (int a=l-1;a>=0;a--)
         {
             if (alpha[a]=='z' && min<=max) {
                                alpha[a]='a';
                                index_z++; }
             else {
                  temp=alpha[a];
                  temp++;
                  alpha[a]=temp;
                  index_z=0;
                  break; }
         }
         if (index_z==l) {
                         l++; }
         return l; 
         }
             
    int main () {
        int len,val,last,check;
        double total=0E+0;
        ofstream outfile("random.txt");
        do {
            system("cls");
        cout << "min = ";
        cin >> min;
        cout << "max = ";
        cin >> max; } while(min>max || max==0);
        len=min;
        last=min;
        val=min;
        for (int i=min;i<=max;i++)
        {
        intialize_values(val);
        check=1;
        while (check==1) {
        for (int k=0;k<len;k++) {
            cout << alpha[k]; }
            cout << "\n";
        total++;
        len=increament(last);
        if (len>last) {
                      last++;
                      check=0;
                      val++; }
                      }
        }
        cout << "\n\n\n";
        cout << "Total Generated = " << total << endl;
        double ch=0E+0;
        for (int i=min;i<=max;i++) {  
        ch+=pow(26,i); }
        if (total==ch)
        cout << "\n\n" << "Task Completed Successfully.";
        cout << "\n\n\n\t\t\tpress any key to exit...";
        getch();
        return 0;
    }
    First, this code will not compile on any version of Visual Studio that is less than 10 years old. The reason is this:
    Code:
      
    #include <iostream.h>
    #include <fstream.h>
    Those header files do not exist in any modern (10 years old or less) version of Visual Studio. They have been replaced with the ANSI standard headers <iostream> and <fstream>.

    Regards,

    Paul McKenzie

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured