Results 1 to 4 of 4

Thread: Problem in a random word function

  1. #1
    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; 
    ) 
    
    )

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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.

  3. #3
    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)

  4. #4
    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;
     )

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2012, 05:07 PM
  2. Generate Random Text In Ms Word
    By Captain Carrot in forum Windows Software
    Replies: 6
    Last Post: 04-09-2010, 05:58 AM
  3. StackOverflow Error and Random function
    By Trini Alvarado in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 01:49 PM
  4. Function for two random numbers
    By Zool in forum Software Development
    Replies: 3
    Last Post: 03-12-2009, 12:39 PM
  5. Random Function to Concatenate 2 strings
    By klite in forum Software Development
    Replies: 3
    Last Post: 14-10-2009, 11:48 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,299,403.26872 seconds with 17 queries