Hi there, I'm new to c++ and im trying to do a project, wich is a letter soup game (its like a word search in a square with loads of other letters).

So far now I have a letter (A-Z) randomizer, wich will put them in an array[l][w] (choosen by the user).

But here is the problem, I need some tips about making a function that will read a .txt file with words AND put them in the array[l][w] (previously made, with a random letter in each position), across and down.

I know how to open a .txt file with a c++ programm, although I see no way to do a function to "organize" those .txt file words inside the array[l][w] I have.

Well, any help is helpfull, and btw, I found this site today and I've learnt more here than in school :P

You could create a struct containing a char and a bool , which will be your 'board'. Then you could randomly assign a position for a word and the direction you want to place it in. Then, check through a loop if another word is positioned in the spaces that the new word will occupy, and if one of the results is true, compare the letter located in that position with the letter of the new word that will occupy that possition, and if there's a match, or the loop query comes out false, put the new letter inside of the board.

I'm having this problem

the word is DOG

AAAAAA
AAAADO
AAAAAA

it places the word outside the array, how do i solve this?
and btw, could you re-explain the process to check if a word is in a certain position?

Thanks very much!

You can try two separate loops: One to check the existence of a word, and the other one to place the word in the grid.

To avoid having the issue you posted, before placing the word, check if the length of the word doesn't exceed the spaces available:

' This boolean will verify if the word can be posted in the
' selected direction (random)
Dim valid As Boolean

Do
   
   ' Here goes the position randomizing algorithm (x = random, y = random)
   
   If word.Length + x > Grid.GetLength(0) Then 'Get the grid's width 
      valid = false
   Else
      valid = true
   End If
While Not valid

' Here goes the loop to add the word to the grid

Ok, I've started making the function again, and now it gives me a problem while i try to compile, its just one, and it's in the function getline...
Isn't it getline("name of the .txt file, max_word_size) ?

I'll leave here the code, thanks for the help.
It's in portuguese, but I'll make a BOLD where it gives the error.
Btw my librarys are (if it helps):

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

void coloca(char nome_do_ficheiro[],int n_palavras,int altura,int largura){
	
	ifstream ficheiro;
	char palavra[21];
	int i=0,aux=0;
	int alt=altura;
	int larg=largura;
	ficheiro.open(nome_do_ficheiro);

	if(ficheiro.is_open()){
		while(!ficheiro.eof()){
			[B]getline("Palavras.txt",20);[/B]
			for(i=0;palavra[i]!='\n';i++)
				aux +=1;
			if(aux>altura && aux>largura){
				cout<<"Nao existem palavras com tamanha suficiente para tal QUADRO!\n";
				cout<<"Reinsira uma nova ALTURA ou LARGURA:\n";
				
			}
			if(aux<altura)
				cout<<"wee";
		}
	}
}

what you're trying to do is read the lines in the txt file, right?

Try this solution

Thanks :D

I have another question (I'm boring, i know :P).

I want to make a time counter, I made a function wich make the system freeze for X seconds (the user will choose), and I'm trying for a few hours and I see no way to make it count the time without freezing the program.

I want to make something similar to this:

time(1000); // will count for 1000 seconds
... //rest of the program bla bla bla
stop time; //will stop counting, when the user hits the key ENTER, and return the seconds it counted

My current function is like this:

void time(int sec){
		
		clock_t endwait;
		endwait = clock () + sec * CLOCKS_PER_SEC;
		while (clock() < endwait){}
}

I've searched for some topics about time.h and clock(), but none were usefull =(
Thanks for any help!

You know... actually that was the reason I joined Daniweb :P

What you wanna do now is do some research about forks, which is calling two or more processes from a main program at the same time (asynchronously)...

Have fun!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.