Path: utzoo!mnetor!motto!andrew From: andrew@motto.UUCP (Andrew Walduck) Newsgroups: comp.lang.c Subject: perror, yet again Message-ID: <266@motto.UUCP> Date: 4 Dec 90 20:16:54 GMT Lines: 30 Peter da Siva writes: >(where the error might not have had anything to do with stdio). In general >the simple code: > > if(!(fp = fopen(...))) { > perror(...); > ... > } >does a perfectly adequate job of printing a usable error message. It would >be nicer to have ferror(fp) return an error number suitable for feeding >to strerror(), but in the meantime it's better than nothing. >-- >Peter da Silva. `-_-' >+1 713 274 5180. 'U` >peter@ferranti.com Actually, a more correct (ANSI) implementation would be: if((fp = fopen(...)) == NULL) { perror(...); ... } as fopen returns NULL upon failure...and NULL is NOT necessarily zero, which is assumed in your code above. Andrew ------------------------------------------------------ | Andrew Walduck | andrew@motto.UUCP | Motorola Canada | ------------------------------------------------------ Brought to you by Super Global Mega Corp .com