1 Replies - 1017 Views - Last Post: 08 May 2015 - 11:44 AM

#1 MuckingFedic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-May 15

Error when trying to read random words from

Posted 08 May 2015 - 10:49 AM

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



#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

Is This A Good Question/Topic? 0
  • +

Replies To: Error when trying to read random words from

#2 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1295
  • View blog
  • Posts: 3,970
  • Joined: 20-March 10

Re: Error when trying to read random words from

Posted 08 May 2015 - 11:44 AM

What type is tbprac ?

generally you convert char* to System::String like so...

String^ str2 = gcnew String(wordone);


Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1