use of if (!cptr) and if (cptr), where cptr is a *)
Dean Rubine
dandb at k.gp.cs.cmu.edu
Tue Jul 25 16:11:17 AEST 1989
A slightly better use of a comma in a while expression is:
while(printf("? "), gets(line) != NULL) {
... whatever ...
}
I think it beats the alternatives:
for(;;) {
printf("? ");
if(gets(line) == NULL)
break;
... whatever ...
}
-- or --
for(printf("? "); gets(line) != NULL; printf("? ")) {
... whatever ...
}
I also occasionally use the comma to save braces:
if((f = fopen(file, "r")) == NULL)
fprintf(stderr, "Can't open %s\n", file), exit(2);
--
ARPA: Dean.Rubine at CS.CMU.EDU UUCP: ...!seismo!k.gp.cs.cmu.edu!dandb
PHONE: 412-268-2613 [ Free if you call from work]
US MAIL: Computer Science Dept / Carnegie Mellon U / Pittsburgh PA 15213
DISCLAIMER: My employer wishes I would stop posting and do some work.
More information about the Comp.lang.c
mailing list