Help: for loop doesn't work?

Discussion in 'C Programming' started by a, Dec 21, 2007.

  1. a

    a Guest

    I'm studying the frequency of 5-letter words composed of {a,b,c,d,e} in a
    string, I wanna build an array recording the frequencies of (aaaaa, aaaab,
    ...., caaaa, ..., eeeee). I find that for loop can work well if I hard-code
    the number, what can I do if I wanna study n-letter word (e.g. n=3, 100,
    3732)?
     
    a, Dec 21, 2007
    #1
    1. Advertising

  2. a

    Thad Smith Guest

    a wrote:
    > I'm studying the frequency of 5-letter words composed of {a,b,c,d,e} in a
    > string, I wanna build an array recording the frequencies of (aaaaa, aaaab,
    > ..., caaaa, ..., eeeee). I find that for loop can work well if I hard-code
    > the number, what can I do if I wanna study n-letter word (e.g. n=3, 100,
    > 3732)?


    I suggest, for a given n, making a single pass through the string, building
    a data structure containing all the defined words and a count of how many
    times each is used. A tree or hash table would work well.

    --
    Thad
     
    Thad Smith, Dec 25, 2007
    #2
    1. Advertising

  3. a

    CBFalconer Guest

    Thad Smith wrote:
    > a wrote:
    >
    >> I'm studying the frequency of 5-letter words composed of
    >> {a,b,c,d,e} in a string, I wanna build an array recording the
    >> frequencies of (aaaaa, aaaab, ..., caaaa, ..., eeeee). I find
    >> that for loop can work well if I hard-code the number, what can
    >> I do if I wanna study n-letter word (e.g. n=3, 100, 3732)?

    >
    > I suggest, for a given n, making a single pass through the string,
    > building a data structure containing all the defined words and a
    > count of how many times each is used. A tree or hash table would
    > work well.


    Take a look at the demonstration application for hashlib, wdfreq.
    Modification should do what the OP wants. hashlib is available,
    GPL licensed, at:

    <http://cbfalconer.home.att.net/download/>

    --
    Merry Christmas, Happy Hanukah, Happy New Year
    Joyeux Noel, Bonne Annee, Frohe Weihnachten
    Chuck F (cbfalconer at maineline dot net)
    <http://cbfalconer.home.att.net>


    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Dec 25, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    14,586
  2. sgharvey
    Replies:
    6
    Views:
    430
    sgharvey
    Mar 23, 2008
  3. Linuxguy123
    Replies:
    1
    Views:
    252
  4. Archie

    Why doesn't this loop work?

    Archie, Jun 25, 2010, in forum: C++
    Replies:
    6
    Views:
    320
    Jonathan Lee
    Jun 25, 2010
  5. Isaac Won
    Replies:
    9
    Views:
    460
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page