Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   (C++) Random name generator (http://zelaron.com/forum/showthread.php?t=27096)

Chruser 2004-01-30 06:56 PM

(C++) Random name generator
 
I'm probably going to convert this to PHP soon to allow new users to see a list of random names that might suit their liking. Anyway, all the names get printed to a file as you can see, so go ahead and poke around with the program a bit if you want it to have a more vast variety of names.

Code:

#include <iostream.h>
#include <string.h>
#include <windows.h>
#include <stdio.h>
#include <fstream.h>

class NAMES{
public:
        char first[8][8];
        char second[8][8];
        char third[8][8];
        char fourth[8][8];
};

NAMES name;
ofstream savefile;

int main(){

        savefile.open("NameList.txt");
        char firstbuffer[5000];
        char secondbuffer[5000];

        int maxnames=1, counter=0, variable=1;
        printf("How many names would you like to generate? ");
        cin >> maxnames;

        srand(GetTickCount());

        strcpy(name.first[0],"Az");
        strcpy(name.first[1],"Ze");
        strcpy(name.first[2],"Ad");
        strcpy(name.first[3],"Do");
        strcpy(name.first[4],"Ra");
        strcpy(name.first[5],"Ba");
        strcpy(name.first[6],"Xo");
        strcpy(name.first[7],"Da");

        strcpy(name.second[0],"rin");
        strcpy(name.second[1],"la");
        strcpy(name.second[2],"mo");
        strcpy(name.second[3],"arx");
        strcpy(name.second[4],"ar");
        strcpy(name.second[5],"do");
        strcpy(name.second[6],"ma");
        strcpy(name.second[7],"mi");
       
        strcpy(name.third[0],"don");
        strcpy(name.third[1],"dran");
        strcpy(name.third[2],"ban");
        strcpy(name.third[3],"na");
        strcpy(name.third[4],"es");
        strcpy(name.third[5],"leth");
        strcpy(name.third[6],"ran");
        strcpy(name.third[7],"al");
       
        strcpy(name.fourth[0],"or");
        strcpy(name.fourth[1],"ar");
        strcpy(name.fourth[2],"ir");
        strcpy(name.fourth[3],"lor");
        strcpy(name.fourth[4],"kir");
        strcpy(name.fourth[5],"des");
        strcpy(name.fourth[6],"del");
        strcpy(name.fourth[7],"mos");

        printf("\n");
        savefile << "The following " << maxnames << " names have been generated:\n\n";

        while(counter<maxnames){
                sprintf(firstbuffer, "%s%s%s",name.first[rand()%8],name.second[rand()%8],name.third[rand()%8]);
                printf("%s",firstbuffer);
                savefile << firstbuffer;
                if(rand()%3==0){
                        sprintf(secondbuffer, "%s",name.fourth[rand()%8]);
                        printf("%s",secondbuffer);
                        savefile << secondbuffer;
                }
               
                printf("\n");
                savefile << endl;
                counter++;
        }
        printf("\nOkay, all done!\n\n");

        return 0;
}


Acer 2004-01-30 07:09 PM

I know this cant be converted to PHP but in C++ if you didnt know a char[][] is the same as *char[];


All times are GMT -6. The time now is 11:33 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.