Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Mon, 28 May 2007 08:12:32 +0100
"Jack Klein" <jackklein@xxxxxxxxxxx> wrote in message news:nudj539a13iksljdr7enmticq9oth4v4bi@xxxxxxxxxx
On Sat, 26 May 2007 13:37:38 +0200, "Army1987" <please.ask@xxxxxx>I am writing a lot of short utilties at the moment.
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 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
.
- Follow-Ups:
- References:
- How to extract a string starting with 'abc' & ending with 'xyz' ?
- From: Umesh
- Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- From: Chris Dollin
- Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- From: Umesh
- Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- From: Army1987
- Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- From: Jack Klein
- How to extract a string starting with 'abc' & ending with 'xyz' ?
- Prev by Date: Re: Segmentation Fault
- Next by Date: Re: Segmentation Fault
- Previous by thread: Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- Next by thread: Re: How to extract a string starting with 'abc' & ending with 'xyz' ?
- Index(es):
Relevant Pages
|