Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes

 
(C++) Random name generator
Reply
Posted 2004-01-30, 06:56 PM
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;
}
"Stephen Wolfram is the creator of Mathematica and is widely regarded as the most important innovator in scientific and technical computing today." - Stephen Wolfram
Old
Profile PM WWW Search
Chruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed itChruser shouldn't have fed it
 
 
Chruser
 



 
Reply
Posted 2004-01-30, 07:09 PM in reply to Chruser's post "(C++) Random name generator"
I know this cant be converted to PHP but in C++ if you didnt know a char[][] is the same as *char[];
Old
Profile PM WWW Search
Acer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzAcer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Acer
 
 

Bookmarks

« Previous Thread | Next Thread »

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

Posting Rules [Forum 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


All times are GMT -6. The time now is 11:32 PM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.