Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Problem in a random word function

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-11-2009
Member
 
Join Date: Aug 2009
Posts: 36
Problem in a random word function
  

I am creating a program in C and I have a problem in my position where I can find a word at random from a dictionary of previously chosen with another function.
Code:
int line_no; 
int i, j; 
char word [20]; 
char caline; 
srand (time (NULL)); 
line_no = rand ()% (long_dic) / / Remember to make a function to find the number of words in the dictionary 
fseek (dic, line_no * long_no, 0); 
rewind (dic); 

while (line_no> 0) 
( 
caline = fgetc (dic); 
if (caline== '\ n') 
line_no -; 
) 

fgets (word, 20, dic); 

for (i = 0; i <long_no; i + +) / / fill the structure test 
( 
es.mot [i] = word [i]; 
) 

es.cache [1] = 1; 

for (j = 1 j <long_no j + +) 
( 
es.cache [j] = 0; 
) 

)

Reply With Quote
  #2  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Problem in a random word function

In your prototype, do not put the keyword "struct".
In fact when you make a structure, you define a "type" of variables.

So your prototype will become:
Code:
 void m_h (FILE * dic, mcache test long_no int, int long_dic)


Then, place the srand (time (NULL)); to the top of your main (). In fact, you do not make this statement only once per program.
Reply With Quote
  #3  
Old 30-11-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: Problem in a random word function

Delcar your structure like this:
Code:
  typedef struct (
 char word [20] / / word to guess
 int cache [20] / / if cache letter value 1 otherwise value 0
 MCache);
and then to declare a structure, you will put:
mCache novalueStructure;


and then in your prototype must be put:
Code:
void m_h (FILE * dic, mCache test long_no int, int long_dic)
Reply With Quote
  #4  
Old 30-11-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: Problem in a random word function

use this :
Code:
fgets (word, 20, dic);

 strcpy (test. word, word) / / we copy word 

 test. cache [1] = 1;

 for (j = 1 j <long_no j + +)
 (
 test. cache [j] = 0;
 )
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem in a random word function"
Thread Thread Starter Forum Replies Last Post
Generate some quality of random number via Random Number Generation function aMADeO! Windows Software 4 13-01-2012 05:07 PM
Generate Random Text In Ms Word Captain Carrot Windows Software 6 04-09-2010 05:58 AM
StackOverflow Error and Random function Trini Alvarado Software Development 5 11-03-2010 01:49 PM
Function for two random numbers Zool Software Development 3 03-12-2009 12:39 PM
Random Function to Concatenate 2 strings klite Software Development 3 14-10-2009 11:48 AM


All times are GMT +5.5. The time now is 08:41 PM.