0

I need to turn the characters in a string that's generated from a data file into *'s and make it visible to the user.

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int numph;		//First number in .dat file saying how many worsd there are
	int wordnum;	//Number of which word in the list the program uses
	int ctr1=0;		//Counter for first loop
	string word, wordstar;	//Word that the user is trying to guess
	int money;		//Number of money

	srand(time(NULL));

	ifstream infile;
	infile.open("words.dat");
	infile>>numph;

	wordnum=rand()%numph+1;
	

	while(ctr1!=(wordnum+1))
	{
		getline(infile, word);
		ctr1++;
	}

As of right now, the code works fine and it gets a random word from my text file. What I want to do is take that word (let's say the word is hotdog) and print it to the scren as ****** or if it were hotdog bun ****** *** respecting spaces as they appear.

I have a start on this with

for (int n=0; n<=t.length()-1; n++)

Any suggestions?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by WaltP
0
for (int n=0; n<=t.length()-1; n++)
    t[n]='*'

Test for SPACE before executing the statement so you can skip over it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.