Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > generating strings

Reply
Thread Tools

generating strings

 
 
Eddie
Guest
Posts: n/a
 
      08-25-2004
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?
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-25-2004
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);
}
}

--


 
Reply With Quote
 
 
 
 
Eddie
Guest
Posts: n/a
 
      08-26-2004
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.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-26-2004
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).

--


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating random strings Mike P ASP .Net 6 05-31-2007 12:52 PM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Generating random strings without duplicates eric.gagnon@loto-quebec.com C++ 7 07-13-2005 10:06 AM
Problem generating functions from C strings Ian Glover Python 0 08-31-2004 09:30 AM
generating strings Eddie C++ 7 08-28-2004 05:31 AM



Advertisments