generating strings

E

Eddie

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?
 
E

Eric Sosman

Eddie said:
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);
}
}
 
E

Eddie

Eric said:
Eddie said:
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.
 
E

Eric Sosman

Eddie said:
Eric said:
Eddie said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top