Re: How to extract a string starting with 'abc' & ending with 'xyz' ?




"Jack Klein" <jackklein@xxxxxxxxxxx> wrote in message news:nudj539a13iksljdr7enmticq9oth4v4bi@xxxxxxxxxx
On Sat, 26 May 2007 13:37:38 +0200, "Army1987" <please.ask@xxxxxx>
wrote in comp.lang.c:


"Umesh" <fraternitydisposal@xxxxxxxxx> ha scritto nel messaggio
news:1180170167.795425.188310@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> /* This is what I can do. If the length of the string starting with
> abc & ending with xyz is known(11 in this case), I can program it as
> follows. But if the length of the string varies between 10 to 50* what
> should I do? Thanks. /
No, it doesn't. "abc45678xyz" doesn't work.
You are only comparing the string with "abc xyz".

>
> //abc?????xyz
> #include<stdio.h>
> #include<stdlib.h>
> int main()
> {
>
> FILE *f,*fp;
> f=fopen("c:/1.txt","r");
> if(f==NULL)
> {
> puts("Error opening file");
Write that to stderr, not to stdout...

No, no, no, NO, NO!!!

The automatic assumption that all programs should write error messages
to stderr is one of the causes of a lot of grief by inconsiderate
programmers.

Programs that generate their primary output to stdout might be
justified in outputting error messages to stderr.

Programs that generate their output to a file, as this one attempts to
do, should indeed generate their error messages to stdout. And that
specifically includes compilers.

I am writing a lot of short utilties at the moment.
I am not sure whether they are easier to use if they send their output to stdout or to a named file passed as a parameter. So of course all the functions are written to take a file pointer, and I can toggle between the two with a couple of lines in main.

One good question is "what is an error?". For instance if the user just types the name of the program, traditionally that prints out a usage message. I always exit with EXIT_FAILURE. The problem is that it is not aways easy to catch that, say from Perl scripts, and you don't necessarily want the usage message beign treated as a vaild output.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.



Relevant Pages

  • Re: How to extract a string starting with abc & ending with xyz ?
    ... But if the length of the string varies between 10 to 50* what ... You are only comparing the string with "abc xyz". ... The automatic assumption that all programs should write error messages ...
    (comp.lang.c)
  • Re: How to extract a string starting with abc & ending with xyz ?
    ... // find a string stating with abc and ending with xyz WORKING ... The compiler ignores indentation; it's used only to make the code ...
    (comp.lang.c)
  • Re: greedy v. non-greedy matching
    ... > xyz 12345 abc ... up to end of the string. ... This doesn't happen when that sub-expression matches the ...
    (comp.lang.perl.misc)
  • Re: String To List
    ... This will fall over if xyz or abc include any of the characters your ... could the string module not use a ... string enclosed by delim (or which begin with delim and end with ...
    (comp.lang.python)
  • Re: Search string and paste it in a new file
    ... occurance of that string in any line should be copied in a new file. ... How are you abc ... this not xyz string ... One way would be to create newfile as an empty file first, ...
    (comp.editors)