mc68020@gilsys.UUCP (Thomas J Keller) (07/18/87)
A friend of mine is writing a program which will, among other things, output some columnar data. He wishes to have the columns alingned so that the decimal points of each number are aligned. His background is in BASIC, and as he points out, in BASIC, a simple PRINT USING command would solve this problem. He asked me for a solution in C. The only thing I've been able to think of is some piece of code which analyzes the output as a formatted string (sprintf'ed), which is passed the column in which the decimal is to be placed, and adjusts the string accordingly. Such a function would be relatively simple to cobble, I suspect, but it seems to me that it would be fairly time consuming at execution time. Is there a better (or already existing) solution to this problem? -- Tom Keller The essential point that so-called "Libertarians" miss in their rabid naivete` is a very sad but true observation: there *ARE* no solutions. UUCP:{ihnp4,ames,qantel,sun,amdahl,lll-crg,pyramid}!ptsfa!gilsys!mc68020
bob@cald80.UUCP (bob) (07/21/87)
[ EAT BITS, LINE-EATER!! ] In article <1085@gilsys.UUCP> mc68020@gilsys.UUCP (Thomas J Keller) writes: > > A friend of mine is writing a program which will, among other things, >output some columnar data. He wishes to have the columns alingned so that >the decimal points of each number are aligned. OK, this is silly but I'll bite (or is that byte?). This simply accomplished with the '[f]printf' statement thusly: printf("%8.3f\n", fnum); or fprintf(fd, "%8.3f\n", fnum); which is the rough equivalent of: PRINT USING ####.###, FNUM This may be oversimplified for the case that you are using but I don't have any further details to go on. --- Thinking quickly, the IBM System Jock # Bob Meyer uttered an incantation in EBCDIC and made # Calspan Advanced Tech. Center the sign of the Terminated Fork. # seismo!kitty!sunybcs!cald80!bob The UNIX Guru only smiled and trapped # decvax!sunybcs!cald80!bob him in a recursive SED script.
brianc@cognos.uucp (Brian Campbell) (07/29/87)
In article <1227@cald80.UUCP> bob@cald80.UUCP (bob) writes: > > printf("%8.3f\n", fnum); > or > fprintf(fd, "%8.3f\n", fnum); Speaking of pet peeves ... this is one of mine! Why do so many programs use fd (which usually stands for "file descriptor") instead of something like fp (FILE pointer) as a parameter to functions which expect a pointer to a file structure? Its bad enough for the C library functions I KNOW expect a pointer, but for functions that someone else wrote (in another source file, of course) it only makes for harder-to-read code. -- Brian Campbell uucp: decvax!utzoo!dciem!nrcaer!cognos!brianc Cognos Incorporated mail: 3755 Riverside Drive, Ottawa, Ontario, K1G 3N3 (613) 738-1440 fido: sysop@163/8