Reading random words from file using ifstream

Hello World!
I am currently writing a password generator in Microsoft Visual Studios 2010 Professional. The section I am having a problem with is the practical password. It is suppose to randomly read 3 words from a text file and then display it in the text box. The program will compile and run but when I hit generate I get "True True True" and not three random words. Then this warning shows up:

Warning C4800: 'char *' : forcing value to bool 'true' or 'false' (performance warning)

Can anyone help point out where I am going wrong?

Thanks!


//Code is from form1.h file. I can post the rest of the code if need be but I just included my includes and the problematic section



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
#include <vector>
#include <fstream>

//PROBLEM SECTION START
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {

		//Initializing the Variables
		double word1, word2, word3;							    
		char wordone[50],wordtwo[50],wordthree[50];
		unsigned seed = time(0);							   //Resets Time for the seed
	

		//Creating the random values
		srand(seed);
		seed = seed + (rand() % 100);
		word1 = (rand() % 34397) + 1;
		seed = seed + (rand() % 100);	   //Seed will randomize the randomize so that we have a random in our random making everything more random
		word2 = (rand() % 34397) + 1;     //This will create 3 random numbers that will then pull 3 differnt words from file
		seed = seed + (rand() % 100);
		word3 = (rand() % 34397) + 1;

		std::ifstream dic1 ( "dictionary1.txt" );
		std::ifstream dic2 ( "dictionary2.txt" );  //Opening up the files      34,397 words in each file      They are the exact same
		std::ifstream dic3 ( "dictionary3.txt" );
		

		//Loops
		for(int i=1; i <= word1; i++)
		{
			dic1 >> wordone;
		}
		
		for(int i=1; i <= word2; i++)
		{	
			dic2 >> wordtwo;
		}
		

		for(int i=1; i <= word3; i++)
		{
			dic3 >> wordthree;	
		}

	    //Where the error is occurring 
		tbprac -> Text = System::Convert::ToString(wordone) + " " + System::Convert::ToString(wordtwo) + " " + System::Convert::ToString(wordthree);


		 
}
//PROBLEM SECTION END



Screenshot of the warnings:
http://imgur.com/rNhR5L4

Picture of the output:
http://imgur.com/LZN2VYi
Last edited on
Topic archived. No new replies allowed.