[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

creating a wordlist

hello,
I have this code here that creates lists, but I want to include numbers too
how can I do that ?
thanks

#include <stdio.h>
int main ()
{
      char a,b,c;
      FILE * fp;

      fp = fopen ("3.txt", "w");
      if ( fp == NULL )
      {
                 printf ("could not open file\n");
                 return 1;
       }
      for ( a='a'; a<='z'; a++ ) {
      for ( b='a'; b<='z'; b++ ) {
      for ( c='a'; c<='z'; c++ ) {
                              fprintf(fp,"%c%c%c\n",a,b,c);
                 }
           }
      }
      fclose (fp);
      return 0;
}
0
aplelois
Asked:
aplelois
1 Solution
 
avinthmCommented:
>  fprintf(fp,"%c%c%c\n",a,b,c);

you can add one more line
fprintf(fp,"%d%d%d\n",a,b,c);

or add one more loop
for(i = 1 ; i<100;i++)
    fprintf(fp,"%d\n",i);
0
 
itsmeandnobodyelseCommented:
You might consider using STL rather than C runtime library

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
    char a,b,c,n;
   
    ofstream fp("3a1n.txt");
   
    if (!fp)
    {
        cout << "could not open file" << endl;
        return 1;
    }
    for ( a='a'; a<='z'; a++ ) {
        for ( b='a'; b<='z'; b++ ) {
            for ( c='a'; c<='z'; c++ ) {
                for ( n='0'; n<='9'; n++ ) {
                    fp << a << b << c << n << endl;
                }
            }
        }
    }
    fp.close();
    return 0;
}

Regards, Alex
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now