generating strings

Discussion in 'C Programming' started by Eddie, Aug 25, 2004.

  1. Eddie

    Eddie Guest

    I searched with my problem but with no results :(

    My question is: how can I generate string, having only simple pattern,
    like, [0-3]mid[4-7]end
    For example tyis pattern should reproduce strings like:

    1. 0min4end
    2. 0min5end
    3. 0min6end
    4. 0min7end

    5. 1min4end
    6. 1min5end
    7. 1min6end
    8. 1min7end

    9. 2min4end
    10. 2min5end
    11. 2min6end
    12. 2min7end

    13. 3min4end
    14. 3min5end
    15. 3min6end
    16. 3min7end

    Is there a alghoritm for it, how can I begin with making this?
    Eddie, Aug 25, 2004
    #1
    1. Advertising

  2. Eddie

    Eric Sosman Guest

    Eddie wrote:
    > I searched with my problem but with no results :(
    >
    > My question is: how can I generate string, having only simple pattern,
    > like, [0-3]mid[4-7]end
    > For example tyis pattern should reproduce strings like:
    >
    > 1. 0min4end
    > 2. 0min5end
    > 3. 0min6end
    > 4. 0min7end
    >
    > 5. 1min4end
    > 6. 1min5end
    > 7. 1min6end
    > 8. 1min7end
    >
    > 9. 2min4end
    > 10. 2min5end
    > 11. 2min6end
    > 12. 2min7end
    >
    > 13. 3min4end
    > 14. 3min5end
    > 15. 3min6end
    > 16. 3min7end
    >
    > Is there a alghoritm for it, how can I begin with making this?


    char buff[sizeof "XminYend"];
    int x, y;
    for (x = 0; x <= 3; ++x) {
    for (y = 4; y <= 7; ++y) {
    sprintf (buff, "%dmin%dend", x, y);
    do_something_with (buff);
    }
    }

    --
    Eric Sosman, Aug 25, 2004
    #2
    1. Advertising

  3. Eddie

    Eddie Guest

    Eric Sosman wrote:

    > Eddie wrote:
    >
    >> I searched with my problem but with no results :(
    >>
    >> My question is: how can I generate string, having only simple
    >> pattern, like, [0-3]mid[4-7]end
    >> For example tyis pattern should reproduce strings like:
    >>
    >> 1. 0min4end
    >> 2. 0min5end
    >> 3. 0min6end
    >> 4. 0min7end
    >>
    >> 5. 1min4end
    >> 6. 1min5end
    >> 7. 1min6end
    >> 8. 1min7end
    >>
    >> 9. 2min4end
    >> 10. 2min5end
    >> 11. 2min6end
    >> 12. 2min7end
    >>
    >> 13. 3min4end
    >> 14. 3min5end
    >> 15. 3min6end
    >> 16. 3min7end
    >>
    >> Is there a alghoritm for it, how can I begin with making this?

    >
    >
    > char buff[sizeof "XminYend"];
    > int x, y;
    > for (x = 0; x <= 3; ++x) {
    > for (y = 4; y <= 7; ++y) {
    > sprintf (buff, "%dmin%dend", x, y);
    > do_something_with (buff);
    > }
    > }
    >

    Hi.
    It was an example with this pattern. I can write thousand examples like
    you wrote.
    I don't know witch pattern user will type. An that the problem.

    It must be an universal algoritm, to process the patern.
    Eddie, Aug 26, 2004
    #3
  4. Eddie

    Eric Sosman Guest

    Eddie wrote:
    > Eric Sosman wrote:
    >
    >> Eddie wrote:
    >>
    >>> I searched with my problem but with no results :(
    >>>
    >>> My question is: how can I generate string, having only simple
    >>> pattern, like, [0-3]mid[4-7]end
    >>> For example tyis pattern should reproduce strings like:
    >>>
    >>> 1. 0min4end
    >>> 2. 0min5end
    >>> [...]

    >>
    >> [hard-wired solution snipped]
    >>
    >>

    > Hi.
    > It was an example with this pattern. I can write thousand examples like
    > you wrote.
    > I don't know witch pattern user will type. An that the problem.
    >
    > It must be an universal algoritm, to process the patern.


    That's what you get for underspecifying your problem.

    You need two principal pieces to do what you want. First,
    you need something to analyze the user's input, break it down
    into fixed and variable pieces, and figure out what values are
    to be substituted in the variable parts. I can't advise you
    here, because you still haven't described the kinds of patterns
    the user may enter. For example, would "[A-F]xxx" be a valid
    pattern? How about "xyz[1-99]" or "[2357]x[1248]y[aeiou]"?
    The general techniques for this kind of analysis come under the
    heading of "parsing," and are not specific to C or to any other
    implementation language (in short, they're off-topic in this
    newsgroup unless and until you run into a C-language problem
    trying to implement the parsing algorithms).

    Once you've analyzed the user's input and built some kind
    of internal representation of it, you need an instance generator
    to produce the actual strings that match the pattern. Again,
    I can't offer much advice because I don't know what kinds of
    patterns you need to handle or what kinds of variable ranges
    are required. In broad outline, though, running through all
    the combinations of N variables each with its own range is
    just like counting on an odometer whose wheels don't all have
    the same number of digits, or like counting on a digital clock
    (where some positions run 0-9 and others only run 0-5).

    --
    Eric Sosman, Aug 26, 2004
    #4
    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. Eddie

    generating strings

    Eddie, Aug 25, 2004, in forum: C++
    Replies:
    7
    Views:
    508
    Karthiik Kumar
    Aug 28, 2004
  2. Ian Glover
    Replies:
    0
    Views:
    256
    Ian Glover
    Aug 31, 2004
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    724
    Malcolm
    Jun 24, 2006
  4. Replies:
    7
    Views:
    486
    Jim Langston
    Jul 13, 2005
  5. Mike P

    Generating random strings

    Mike P, May 31, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    301
    Samuel R. Neff
    May 31, 2007
Loading...

Share This Page