Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!nike!aurora!ames!hplabs!sdcrdcf!burdvax!psuvax1!vu-vlsi!cbmvax!higgin From: higgin@cbmvax.cbm.UUCP (Paul Higginbottom) Newsgroups: net.micro.amiga Subject: Re: possible bug in 1.1 file redirection Message-ID: <564@cbmvax.cbmvax.cbm.UUCP> Date: Sun, 3-Aug-86 13:59:34 EDT Article-I.D.: cbmvax.564 Posted: Sun Aug 3 13:59:34 1986 Date-Received: Mon, 4-Aug-86 07:24:49 EDT References: <5420@topaz.RUTGERS.EDU> Reply-To: higgin@cbmvax.UUCP (Paul Higginbottom) Organization: Commodore Technology, West Chester, PA Lines: 58 Keywords: file redirection , bug In article <5420@topaz.RUTGERS.EDU> mende@topaz.RUTGERS.EDU (Mende) writes: >I am programming on an Amiga with Aztec C (developer's package) and have come >accross the following problem. It may be a bug in the Aztec compiler or a >buf in AmigaDOS. Note the programmer's ego - it couldn't be your program! 8-) >My program is simply a filter to do a word-wrap on standard >ASCII files. The program below is just enough to demonstrate the problem. >The below program should read standard input (line by line) and output it >(line by line) to standard output. When I compile this (or the filter) and >issue the command: THRU Everything is fine. If I issue the command: THRU FOO >then: TYPE FOO >the output is different. The end is cut off. Why would this work if the >IO is sent to the screen but not to a file? I have written filters before >but they worked purely on a getchar()/putchar() basis. Could I be misusing >the fgets()/fputs() commands? > >P.S. THRU * works fine too! >*/ > >#include >#define MAXLINE 100 >main() /* Program thru.c */ >{ > register char *line[MAXLINE]; > > while ( (fgets(line, MAXLINE, stdin)) != 0 ) > fputs(line, stdout); >} > > > Bob Mende > posting for Tom Limoncelli > >ARPA: MENDE@AIM.RUTGERS.EDU >UUCP: {anywhere}!{topaz!caip}!aim!mende 1) register char *line[MAXLINE] is meaningless. What you've declared is an array of pointers to chars, not an array of chars, and I expect the compiler ignores the attempt to put an array in a register 8-). 2) fgets() returns the address of the buffer (in this case 'line') if all goes well, and NULL upon EOF or an error. You have not externed fgets() but if you're compiling with the 32 bit ints option, all will work (although it's sloppy). I'm not attacking your programming style, I realize you just gave the example to get the message across. BUT - if you're using 16 bit ints and compiled the above, you would get unpredictable results, e.g if the low (or high, I'm not sure) word of the result of fgets which is not externed is 0 the program will stop (probably not what you want). Hope this helps, Sincerely, Paul Higginbottom Disclaimer: I do not work for Commodore, my opinions are my own, and I probably won't be around to see any replies to this.