Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ucsd!ucsdhub!hp-sdd!ncr-sd!se-sd!rns From: rns@se-sd.sandiego.ncr.com (Rick Schubert) Newsgroups: comp.lang.c Subject: Re: Memory Allocation Summary: error messages go to stderr Message-ID: <1774@se-sd.sandiego.ncr.com> Date: 10 Feb 89 21:35:07 GMT References: <1435@arctic.nprdc.arpa> Reply-To: rns@se-sd.sandiego.NCR.COM (Rick Schubert(AEP)) Distribution: usa Organization: NCR Corp. Systems Engineering, San Diego Lines: 21 [Sorry if this is a duplicate; I don't think my original got out.] My standard 2-day waiting period is up, and no one else has made this comment, so here goes: In article <1435@arctic.nprdc.arpa> snguyen@nprdc.arpa (Son Nguyen) writes: > if ((var = (struct abc *) malloc (sizeof (struct abc))) == NULL) { > printf ("ERROR: Can't allocate memory for 'var'\n"); > exit (1); > } That should be: fprintf (stderr, "ERROR: Can't allocate memory for 'var'\n"); Error messages should be written to stderr, not stdout (which is where printf writes); that's what stderr is for. This is important (on systems that have pipes) if stdout is piped into another program or (on systems that have file redirection) if stdout is redirected to a file. (But it's good to see that you've checked the return from malloc!) -- Rick Schubert (rns@se-sd.sandiego.NCR.COM)