Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pacbell!att-ih!ihnp4!inuxc!iuvax!pur-ee!uiucdcs!uxc.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Pascal --> C question Message-ID: <225800016@uxe.cso.uiuc.edu> Date: 21 Mar 88 13:58:00 GMT References: <302@goofy.megatest.UUCP> Lines: 46 Nf-ID: #R:goofy.megatest.UUCP:302:uxe.cso.uiuc.edu:225800016:000:1556 Nf-From: uxe.cso.uiuc.edu!mcdonald Mar 21 07:58:00 1988 Rahul Desi wrote the following C program: /* A "Hello world" program in three movements */ #include main() { printf("He"); fflush(stdout); printf("llo"); fflush(stdout); printf(" wor"); fflush(stdout); printf("ld"); fflush(stdout); printf("\n"); } and ran it in batch mode on VMS. He got as output: He llo wor ld I ran it interactively, and it output "Hello world" [sic] (He forgot the canonical ! ;-) (hey! that's a great typo! a wink!) ) I ran it after doing a $define sys$output hello.out . and when I type the hello.out file I get He llo wor ld The file "hello.out" is a standard VMS text file. I think that the four- line file the program creates is correct. Remember that Dhesi didn't put a printf("Hello world\n"); statement in his file. He wrote it so that it was split into four records by the flushes. He got the four records. Because standard VMS text files always have records which logically end in carriage-return line-feed pairs, it prints the way it does. This seems to be correct behaviour: a flush terminates a record. If he wanted to output to a file where a flush did not terminate a record, but rather a line-feed alone did, he should open the file as "byte-stream terminated by line-feed". This is how VMS C by default opens text files. But he didn't open the file himself, he used stdout, which VMS opens in a predefined way, which appears to differ if it is going to the screen or a disk file. All this goes to prove is that VMS is not Unix. The VMS C compiler isn't broken. Doug McDonald