(none)

Jit Keong Tan jit at SLIC.CELLBIO.DUKE.EDU
Tue Nov 27 09:08:17 AEST 1990


Subject: RE: Picture Specifications for UNIX

I am not sure what does it mean by Picture Specifications.
But the easiest way to write your own itoa function.


so while calling printf function, insert your own itoa 
function.

NOTE: I am writing the code as I think without any compilation, this
is just to demonstrate how one can invent one's printf pattern.

-------------------------------------------------------
char *itoa(int, char *,int);


printf("Number = %d, Pretty number = %s \n", 
	NUMBER_TO_PRINTED,itoa(NUMBER_TO_PRINTED, buffer, PRETTY_NUMBER));

where itoa() is :

char *itoa(int number, char *buffer, int mode)
{

	static char *ch;
	int pp;

/******* Make sure buffer is large enough to hold the output format *******/

	ch = buffer;

      switch (mode) {
	case PRETTY_NUMBER:

		pp = 0;
		do {
			pp++;
			*ch++ = number % 10 + '0';	/* works for ASCII */
			if ( (pp % 3) == 0) *ch++ = ',';/* Add comma */
		} while ( ( number /= 10) );

		if (number < 0) *ch++ = '-';
		*ch = '\0';

/* The number will come out reverse, and there will be one extra
comma if the number is a multiple of 3 digits. But you get the idea,
the correct version is left as an exercise.  I don't feel like
making my brains to work today :-)
*/
		break;

	case BINARY: 
		/* Print BINARY ! */
		break;
	case ETC:  /* Be innovative ! */
		break;
	default :
		*ch = '0';
		*++ch = '\0';
		break;
	}

	return buffer;
}

--------------------------------------------------------
Jit Keong Tan     | internet: jit at slic.cellbio.duke.edu
(919) 684-8098    | bitnet  : tan00001 at dukemc.bitnet
--------------------------------------------------------
U.S. Mail:
Duke University Medical Center
Department Of Cell Biology
Box 3709
Durham, NC 27710



More information about the Comp.sys.sgi mailing list