Re: Goto still considered helpful
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Sat, 20 Oct 2007 17:59:05 -0400
santosh wrote:
Keith Thompson wrote:
Tor Rustad <tor_rustad@xxxxxxxxxxx> writes:
CBFalconer wrote:
[...]
You don't need all that confusing local declaration of
variables, etc. Consider:
int fcopy(char const *dst, char const *src) {
FILE *sf, *df;
int ch
if (sf = fopen(src, "r") { /* text files */
if (df = fopen(dst, "w") {
while (EOF != (ch = getc(sf))) putc(ch, df);
fclose(df);
}
fclose(sf);
}
return sf && df; /* non-zero for success */
}
which I consider more readable and safer than your version. :-)
This is good-weather code, and has nothing to do with "safe"
code in production.
Just on my first read, I think you need to consider:
- fopen failure
- getc failure
- putc failure
far more carefully.
I believe it already handles fopen failure correctly.
I agree about getc and putc.
The code snippet wont compile.
Yes, there are a couple of missing ')'s. Penalty for typing into
the newsreader. The above errors (apart from putc) already force
function termination.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- Goto still considered helpful
- From: James Dow Allen
- Re: Goto still considered helpful
- From: Army1987
- Re: Goto still considered helpful
- From: Malcolm McLean
- Re: Goto still considered helpful
- From: Kenneth Brody
- Re: Goto still considered helpful
- From: Peter Pichler
- Re: Goto still considered helpful
- From: Tor Rustad
- Re: Goto still considered helpful
- From: Keith Thompson
- Re: Goto still considered helpful
- From: santosh
- Goto still considered helpful
- Prev by Date: Re: Goto still considered helpful
- Next by Date: Re: How can i read the stack frames of running process?
- Previous by thread: Re: Goto still considered helpful
- Next by thread: Re: Goto still considered helpful
- Index(es):
Relevant Pages
|