TweetFollow Us on Twitter

Print Window
Volume Number:2
Issue Number:10
Column Tag:ABC's of C

A Print Window for Debugging

By Bob Gordon, Apropos Publications, Contributing Editor

In the first column we did the traditional first C program and wrote "hello, world" on the screen using the C function printf(). Since then we have examined some C programming concepts and gotten a window and menus to appear on the screen. Beginning with this column we are going to spend some time writing to a window. I am going to start by writing some text. My main reason for wanting to start with text is the complaint I had with the LightSpeed C compiler: there was no way to write to the screen and still see the menus and window you put there. Since one of the most useful debugging tools is the ability to print out the value of variables and to get some indication of where you are in a program, I thought a useful and instructive function to write would be a printf()-like routine that would not take over the entire screen. I called the function printw() (print to window), and it turned out to be fairly complex and include some rather obscure C. It is not that important if you don't follow the entire explanation. There is a lot of standard C presented in this month's column, and the function will prove to be quite useful. Type it in and get it working. By the way, it is not finished, and we will add to it in subsequent installments.

C Text Conventions

C compilers provide an escape mechanism in text to allow the placement of non-displayable characters inside a string. The escape character is the backslash (\). Certain characters preceded by the backslash result in a control character. Note that the control character is placed in the string replacing the backslash and the following character. These sequences are referred to in The C Programming Language as character constants.

Sequence ASCII Description

\n LF line feed

\t HT horizontal tab

\v VT vertical tab

\b BS backspace

\r CR carriage return

\f FF form feed

\" double quote

\' single quote

\\ backslash

To use these, just place the sequence where you wish to have the character:

 char   c;
 char   *s;

 c = '\b';
 s = "\nhello, world\n";

You may also follow the backslash with one to three octal (octal!) digits to generate any arbitrary character. You will most often see '\0' which is the null character.

Fig. 1 Our printw() window is out of the way

Loops

Except for the event loop, we have not had much reason to use loops so far. This month, however, there are two functions that scan through strings, and I have used two C looping constructs.

To have a loop that tests before the code is run, use the while loop.

 while (expression )
 statement

The expression may be any C expression. If the expression is true (non-zero), the statement is executed. If the expression is false (zero), the loop is terminated and the expression is not executed.

A second type of loop tests at the bottom. This means that the body of the loop is executed at least once.

 do
 statement
 while (expression  );

In both these loops the statement may consist of any number of C statements surrounded by braces ({}).

Pointers

It is often necessary to loop through strings. Remember that a C string is an array of bytes terminated by the null character ('\0'). A string (or an array) is usually accessed as a pointer. For example, given this declaration:

 char   s[20];   /* an array of twenty bytes */

Assume s is a string with a terminating null character. We could loop through s by:

 while (s[i])

or

 while (*s)

The first form uses an index to access each byte or character. The second uses the name of the array by itself as a pointer. The name of an array is the address of the element zero. The * uses the contents of the pointer and accesses that address to retrieve the value stored there. In our example, s[0] equals *s.

The other operator heavily involved with pointers is the address of operator, &. This returns the address of any object.

 short  x;/* declare x  as a short */
 short  *px;/* px  is a pointer to a short */

 px = &x; /* assign address of x to px */

We have used the address of operator when passing structures to toolbox functions.

Pointer Arithmetic

C knows the size of the object to which a pointer points, so it can handle the process of pointing at the next (or previous) object automatically. If px is a pointer, px += 1 increments px by the size (in bytes) of the object to which px points. If px points to a structure containing 72 bytes, px += 1 adds 72 to the current value of px.

At this point, I should introduce two additional and rather unusual C operators. Since incrementing and decrementing are done so often, C has special operators for these operations.

 ++px;  /* increment px */
 --px;  /* decrement px */

These are unary operators. What is unusual about them is that they may be placed before or after the variable, and the placement affects when the operation is carried out relative to the variables use in an expression. If placed before the variable, the increment (or decrement) operation is done before the variable is used. If placed after, the increment/decrement is done after the variable is used.

 short  x, y, z;

 x = 5;
 y = ++x;

 x = 5;
 z = x++;

In both cases above, x ends up equal to 6. In the first, y is also six, but in the second z is five as the variable, x, is used and then incremented. In many cases it does not matter which you use, but when it does matter, it is a likely source of problems. The notation is often used because it is compact and may result in very efficient code, depending on the compiler. The increment and decrement operators work correctly with pointers: they increment or decrement by the size of the object to which the pointer points.

Writing to a Window

The other point of this month's column was to start using some QuickDraw functions to write to the screen. I only needed DrawChar() and DrawString() to get text on the screen. You will also note a call to ScrollRect(), but it is being used in a very simple way, and I think it would be best if we pretend it isn't really there this month.

What is important to note about writing to the screen is that all writing takes place in objects called GrafPorts. A GrafPort is a complex structure that contains all sorts of information about the environment that the QuickDraw routines will use. In general you need not worry about the individual members of the GrafPort structure as there are functions that provide access to them. Only one GrafPort is active at a time: the QuickDraw routines do not have a parameter that specifies which GrafPort to use; they use the one indicated by SetPort(). This is done near the beginning of printw(). printw() also obtains the current GrafPort and restores it when it is done.

The Macintosh Toolbox with C book has a couple of pages describing how to create and dispose of a GrafPort. What they do not make clear is that by creating a window you have created a GrafPort. If you examine the window structure, WindowRecord, you will see that the first member is a GrafPort and that a WindowPtr is a GrafPtr which is a pointer to a GrafPort. So if you have a window, you have a GrafPort, and you can draw to it.

This Month's Program

This month's program is last month's program [See August 1986, issue of MacTutor. -Ed] with the addition of two functions: printw() and ntoa(). I placed calls to printw() inside domouse() just so I could have printw() work under something I could control. At the moment it does not print out anything interesting, but you can use printw() to examine a variety of variables in the program. Since most of the program is exactly the same as last month's, I am going to discuss only the two new functions.

As we all know, one of the problems with using C on the Mac is the incompatibility between C strings and Pascal strings. These functions use C strings so you can use them in your program without any special worry. printw() does any necessary conversions to Pascal strings before it calls Toolbox routines.

ntoa()

ntoa() converts numbers to ASCII. It is a fairly general purpose routine that handles signed or unsigned numbers and shorts and longs. It begins by checking for signed values. If the variable is signed, it converts it to its absolute value and sets a flag. Then there is a while loop that mods and divides to convert the number to ASCII. It stops when the number goes to zero. At this point the number has been converted but it is in the string backwards. A do-while loop is used to copy the string into the correct order. Finally, the null character is put on the end of the string.

One thing to note is the variable i. It is initialized when it is declared. Automatic and register variables have garbage values until they are initialized either in code or when they are declared. The effect of initializing an automatic variable is the same as setting its value in the code, but sometimes it is clearer to use initialization. Also note the use of casts to convert the value to the correct size. There will be more on this in the discussion of printw().

printw()

This routine contains a certain amount of C esoterica. If you are not interested in how C handles parameters, feel free to skip this discussion. On the other hand, the routine should prove quite useful, and it does follow the tradition established in Kernighan and Ritchie of learning C by examining standard C functions.

printw() mimics the standard C library function printf(). printf() prints to the "standard output device" and can take a variable number of parameters. printw() prints to its own window and also can take a variable number of parameters.

One parameter is required in printf() (and printw()), the control string. This is a string that is printed and may contain a variety of conversion specifications. These have varying complexity and can specify justification, the type and size of a variable to be printed, the width of the field in which to print, and whether the variable is signed or unsigned. Each specification starts with a percent sign (%) and ends with a conversion character. printw() provides a limited subset of these:

d decimal

u unsigned decimal

c a single character*

s a string*

x unsigned hexadecimal*

*Not yet implemented.

You may place a lower case l ('l') before the u or d to indicate the variable is a long rather than a short.

As printw() prints to its own window, the first time it is called it creates the window. The window is set at the bottom of the screen. This is hard coded in the call to SetRect(); change the position or size as desired. In fact it might be useful to have a code in the control string that allows the rectangle to be defined on the fly. To know whether or not the window has been created, it checks the value of pw, the WindowPtr. This is a static variable (static variables retain their values between calls), and actually C guarantees that all statics will be initialized to zero. If pw is zero, the window does not exist so it is created. C also guarantees that no legal pointer will have a value of zero, so we know the value returned by NewWindow() will be non-zero.

I used GetFontInfo() to retrieve the line size. Since this does not change, the computation of line size could be moved inside the window opening code.

Parameter Passing

C generally passes parameters on the stack. LightSpeed C does this. Mac C passes parameters in registers if it can, however you can force it to pass parameters on the stack if you need to. Mac C also has a special, non-standard way of indicating that a function will receive a variable number of parameters. See note at the end.

As the LightSpeed C manual points out, the parameter passing conventions are a de facto standard so what follows may not apply to your compiler. When a function is called, the parameters are placed on the stack from right to left:

 afunc(a,b,c,d);   /* call of afunc() with four                
 parameters */

Picture of stack d

 c
 b
 a
 SP---> return address

As illustrated, d is pushed first, then c, and so on (remember, the stack grows down in memory). This means the first parameter (a) is the last one placed on the stack and is in a known position just above the return address. If the first parameter contains information about the number of parameters passed on a call, we can write a function that can handle a variable number of parameters. Unlike Pascal, the process of cleaning up the stack after the call is handled by the caller. Since the caller knows how many parameters were passed (or where the stack pointer was before the call), the stack can be correctly maintained. printf() and printw() use the percent signs in the control string to determine the number of parameters passed.

The problem now is to determine where the parameters are. The control string is passed as a pointer. That is, we have the address of the string. What we need is the address of the pointer (the parameter). This is obtained by using the address of operator in the line:

 ts = &s;

ts is now a pointer to a pointer to a string. This is converted to a ordinary pointer with a cast on the next line. Finally, we add the size of a pointer to the value to leave us pointing at the second parameter on the stack.

Back to printw()

The major portion of printw() is a case statement that examines every character in the control string. If the character is not a new line or a conversion character, it is drawn in the window (with DrawChar()). If it encounters a new line (\n), it determines if it should scroll the window or not and moves the drawing position to the beginning of the next line. This is where the line size, computed at the beginning of the function, is used. If it finds a percent sign, it begins to determine the kind of parameter.

I think most of the code is fairly straightforward. When the a u or d conversion character is detected, it must extract a number from the parameters. At this point we know if the number is a long or not (having previously detected an 'l' if it is to be a long). Since we have a pointer to a char instead of a parameter, a cast is used to obtain the correct size number.

 num = *(ulong*)ps;

ps is a pointer to a character. The cast (ulong*) converts it to a pointer to an unsigned long (ulong was added to abc.h), and the '*' to the left of the cast dereferences the pointer to obtain the value. Note that the variable num is an unsigned long which is what ntoa() expects.

Another less obvious construction is in the call to ntoa(). ntoa() receives four parameters one of which is a flag indicating whether the value is signed or not (it is True if signed). The call to ntoa() contains

'u' - *s

for the signed parameter. If the conversion character (*s) is a 'u,' this results in a value of zero or False, if it is a 'd,' it will be non-zero and True.

Also note that each time we extract a parameter we increment the parameter pointer, ps, by the size of the parameter. This is an excellent place for the code to get confused.

Note for Mac C

To create a function that deals with a variable number of parameters Mac C uses a special construct. The last parameter in the function must be " " as in:

  int printf(format, arg,  )

If the routine is external (not included in the file in which it is called), it must be declared:

 extern int printf( );

Another difference in Mac C relevant to printw() is the interpretation of the \n character. LightSpeed C (and standard C) interpret the \n as a line feed; Mac C translates it to a carriage return. This should pose no problem if you use the '\n' consistently.

Refer to Appendix A of the Mac C Programmer's Guide for details.

A Problem

In the domouse() routine that passes control to different routines depending on where the mouse is, there are a number of printw() calls. They are there simply to have something print out. Also in this routine is a change from last month's program caused by the addition of the printw(). If the mouse is in the window content area, it may be in the printw() window or some other window. We normally would be interested only in the other window. I added an if-statement here to ensure response only if in the correct window, but this is not a very good solution. Another solution would be to declare the pointer to the printw() window as a global and check that the mouse is not in that window. A third possibility would be a function that checks for the printw() window. Perhaps the best would be a replacement for FindWindow() that could check for the printw() window. This way when it came time to remove the printw(), you could simply link in the correct version of FindWindow().

Current Version of abc.h

/* abc.h 
 *
 * Local definitions to improve readability
 *
 */
 
#define True1
#define False    0
#define Nil 0
#define and &&
#define or||
#define not !
#define equals   ==
#define notequal !=


/* unsigned longs and shorts
 * (unsigned longs may not be 
 *  available with all compilers
 */
#define ushort   unsigned short
#define ulong    unsigned long


/* General purpose external routines 
 * String conversion routines 
 * return a pointer to a char 
 */
extern  char*CtoPstr();
extern  char*PtoCstr(); 
Program with printw()
/* Sending text to window with
 *  function that accepts a variable
 * number of parameters
 *
 * Compiled with LightspeedC
 * Note LS puts 'Mgr' in h file names!
 * (load MacTraps into the project first.)

 * Important note for Mac C users:
 * Every place you see event->where,
 * replace it with &event->where
 */
 
 #include "abc.h"
 #include "Quickdraw.h"
 #include "EventMgr.h"
 #include "WindowMgr.h"
 #include "MenuMgr.h"
 
 /* defines for menu ID's */
 
 #defineMdesk    100
 #defineMfile    101
 #defineMedit    102
 #defineMwind    103
 #defineMtest    104
 
 /* Global variables */
 
 MenuHandle menuDesk;/* menu handles */
 MenuHandle menuFile;
 MenuHandle menuEdit;
 MenuHandle menuWind;
 MenuHandle menuTest;
 
 WindowPtrtheWindow;
 WindowRecord    windowRec;
 Rect   dragbound;
 Rect   limitRect;
 
main()
{
 initsys(); /* system initialization */
 initapp(); /* application initialization */
 eventloop();
}

/* system initialization 
 * note use of hard coded screen sizes
 * with LightspeedC.  This will work
 * with other compilers but is not
 * good practice
 */
initsys() 
{
 InitGraf(&thePort); /* these two lines done */
 InitFonts();    /* automatically by Mac C */
 InitWindows();
 InitCursor();
 InitMenus();
 theWindow = Nil;/*indicates no window */
 SetRect(&dragbound,0,0,512,250);
 SetRect(&limitRect,60,40,508,244);
}

/*
 * application initialization
 * Sets up menus.
 * Each menu is a separate group
 * of lines.  Note the last menu
 * is appended but not inserted.  This
 * makes it part of the menu list but 
 * not in the menu bar.
 */
initapp()
{
 menuDesk = NewMenu(Mdesk,CtoPstr("\24"));
 AddResMenu (menuDesk, 'DRVR');
 InsertMenu (menuDesk, 0);
 
 menuFile = NewMenu(Mfile, CtoPstr("File"));
 AppendMenu (menuFile, 
 CtoPstr("Open Window/M;Close Window/X;Quit/Q"));
 AppendMenu (menuFile, 
 CtoPstr("(-;Show Test;(Hide Test"));
 InsertMenu (menuFile, 0);
 
 menuEdit = NewMenu(Medit, CtoPstr("Edit"));
 AppendMenu (menuEdit, 
 CtoPstr("Undo;(-;Cut;Copy;Paste;Clear"));
 InsertMenu (menuEdit, 0);
 
 menuWind = NewMenu(Mwind, CtoPstr("Window"));
 AppendMenu (menuWind, 
 CtoPstr("Hide;Show;New Title"));
 InsertMenu (menuWind, 0);
 
 menuTest = NewMenu(Mtest, CtoPstr("Test"));
 AppendMenu (menuTest, 
 CtoPstr("Pick;One;Of;These"));
 
 DrawMenuBar();
}
 
/* Event Loop 
 * Loop forever until Quit
 */
eventloop()
{
 EventRecordtheEvent;
 char   c;
 short  windowcode;
 WindowPtrww;
 
 while(True)
 {
 if (theWindow)      /* this code is here to prevent */
 { /* closing an already closed */
 EnableItem(menuFile,2);  /* window! */
 DisableItem(menuFile,1);
 }
 else   
 { 
 EnableItem(menuFile,1);
 DisableItem(menuFile,2);
 }
 
 if (GetNextEvent(everyEvent,&theEvent))
 switch(theEvent.what)  
 { /* only check key and */
 case keyDown:   /* mouse down events */
 if (theEvent.modifiers & cmdKey)
 {
 c = theEvent.message &   charCodeMask;
 domenu(MenuKey(c));
 }
 break;
 case mouseDown:
 domouse(&theEvent);
 break;
 default:
 break;
 }
 }
}


/* domouse
 * handle mouse down events
 */
domouse(er)
 EventRecord*er;
{
 short  windowcode;
 WindowPtrwhichWindow;
 short  ingo;
 long   size;
 ushort t1 = 0xFFFF;
 short  t2 = 0xFFFF;
 
 windowcode = FindWindow(er->where, &whichWindow);
 switch (windowcode)
 {
 case inDesk:
 if (theWindow notequal 0)
 {
 HiliteWindow(theWindow, False);
 DrawGrowIcon(theWindow);
 }
 printw(" In Desk %d %ld %d ",10,123L,-456);
 break;
 case inMenuBar:
 printw("\nIn MenuBar %u %d ",t2,t1);
 domenu(MenuSelect(er->where));
 break;
 case inSysWindow:
 SysBeep(1);
 break;
 case inContent:
 printw("\nIn content %ld %d",700000,700000);
 if (whichWindow equals theWindow)
 {
 HiliteWindow(whichWindow,True);
 DrawGrowIcon(theWindow);
 }
 break;
 case inDrag:
 DragWindow(whichWindow, er->where, &dragbound);
 DrawGrowIcon(theWindow);
 break;
 case inGrow:
 /* not included this month */
 break;
 case inGoAway:
 ingo = TrackGoAway(whichWindow,er->where);
 if (ingo)
 {
 CloseWindow(whichWindow);
 theWindow = Nil;
 }
 break;
 }
}

/* domenu
 * handles menu activity
 * simply a dispatcher for each
 * menu.
 */
domenu(mc)
 long   mc; /* menu result */
{
 short  menuId;
 short  menuitem;
 
 menuId = HiWord(mc);
 menuitem = LoWord(mc);
 
 switch (menuId)
 {
 case Mdesk  : 
 break; /* not handling DA's */
 case Mfile  : 
 dofile(menuitem);
 break;
 case Medit  : 
 break;
 case Mwind : 
 dowind(menuitem);
  break;
 case Mtest : 
 dotest(menuitem);
 break;
 }
 HiliteMenu(0);
}

/* dofile
 * handles file menu
 */
dofile(item)
 short  item;
{
 char   *title1; /* first title for window */
 Rect   boundsRect;
 
 switch (item)
 {
 case 1 : /* open the window */
 title1 = "ABC Window";
 SetRect(&boundsRect,50,50,300,150);
 theWindow = NewWindow(&windowRec, &boundsRect,
 CtoPstr(title1),True,documentProc,
 (WindowPtr) -1, True, 0);
 DrawGrowIcon(theWindow);
 PtoCstr(title1);
 DisableItem(menuFile,1);
 EnableItem(menuFile,2);
 break;
 
 case 2 : /* close the window */
 CloseWindow(theWindow);
 theWindow = Nil;
 DisableItem(menuFile,2);
 EnableItem(menuFile,1);
 break;
 
 case 3 : /* Quit */
 ExitToShell();
 break;
 
 case 5 : /* Install additional menu */
 InsertMenu(menuTest,0);
 EnableItem(menuFile,6);
 DisableItem(menuFile,5);
 DrawMenuBar();
 break;
 
 case 6 : /* remove additional menu */
 DeleteMenu(Mtest);
 EnableItem(menuFile,5);
 DisableItem(menuFile,6);
 DrawMenuBar();
 break;
 }
}

/*
 * dowind
 * handles window menu 
 * Note that each case contains an
 * if testing the existance of the
 * window.  This could be written
 * with one if before the switch.
 */
dowind(item)
 short  item;
{
 char   *title2; /* second title for window */
 
 switch (item)
 {
 case 1 : /* Hide */
 if (theWindow)
 HideWindow(theWindow);
 break;
 case 2 : /* Show */
 if (theWindow)
 ShowWindow(theWindow);
 break;
 case 3 : /* Change title */
 if (theWindow)
 {
 title2 = "A Different Title";
 SetWTitle(theWindow, CtoPstr(title2));
 PtoCstr(title2);
 }
 break;
 }
}

/* dotest
 * Handles new menu.
 * All this does is mark menu
 * items if they are not marked and
 * unmark them if they are.
 */
dotest(item)
 short  item;
{
 short  mark;
 
 GetItemMark(menuTest,item,&mark);
 if (mark)
 CheckItem(menuTest,item,False);
 else
 CheckItem(menuTest,item,True);
}

/* Displays strings and numbers in a 
 * special window
 * This function is designed to receive
 * a variable number of parameters. The 
 * number is computed by the number of
 * percent signs in the control string.
 * If the number of parameters following the 
 * control string does not match the 
 * number of percent signs, expect 
 * the unexpected.
 */
printw(s)
 char   *s; /* the control string */
{
#define Bufsz  14/* size of buffer to hold */
 /* converted numbers */  

static Rect boundsRect; /* variables for */
static Rect windowRect; /* defining printw */
static WindowRecordwrc;   /* window, pw is */
static WindowPtr pw = 0;  /* initialized to 0 */
WindowPtr oldport; /* save grafport here */
short   linesz;  /* size of line */
FontInfoinfo;    
short   nl;
Point   pt;
RgnHandle updrgn;/* needed for scrolling */
char    numAsStr[Bufsz];  /* number conversion */
short   nsz;/* size of numbers (2 or 4) */
char    **ts;    /* ptr to ptr to ctrl string */
char    *ps;/* ptr to parameters */
ulong   num;/* for number conversion */
short   convchar;/* found conversion char */
short   islong;  /* number is a long */
 
/* Window rectancgle coordinates */

#define wl0
#define wr512
#define wt250
#define wb342
 
 
GetPort(&oldport); /* save current graph port */
GetFontInfo(&info);/* compute line height */
linesz = info.ascent + info.descent;
if (pw equals 0) /* if window does not exist*/
 { /*  open it */
 SetRect(&boundsRect,wl,wt,wr,wb);
 pw = NewWindow(&wrc, &boundsRect,
 CtoPstr(""),True,plainDBox,
 (WindowPtr) -1, True, 0);
 nl = linesz;    /* move down one line as */
 } /*  writing will be above */
 else   /*  boundary.  No need to  */
 nl = 0;/*  move line if  open */
 SetPort(pw);    /* Set port to this window */
 Move(0,nl);/* Move (relative) */
 
 ts = &s; /* get address of control string ptr */
 ps = (char *)ts;/* convert to pointer to params */
 ps += sizeof(long); /* skip over control string pointer*/
 while (*s) /* loop until end of control string */
 {
 switch (*s)/* check each character */
 {
 case '%' : /* percent sign: check conversion */
 s++;   /* point to next char */
 convchar = False; /* initialize conv  loop */
 islong = False;
 do {   /*  until reach conv char */
 switch (*s)
 {
 case 'l' : /* indicates a long */
 islong = True;
 s++;
 break;
 case 'u' : /* unsigned decimal */
 case 'd' : /* signed decimal */
 if (islong)/* extract number  */
 {
 num = *(ulong*)ps;
 nsz = sizeof(long);
 }
 else
 {
 num = *(ushort*)ps;
 nsz = sizeof(short);
 }
 ps += nsz; /* point to next param */
 /* convert number and write it to 
  *   window
  */
 ntoa(num,nsz,'u' - *s,numAsStr);
 DrawString(CtoPstr(numAsStr));
 convchar = True;
 break;
 /* strings, individual chars and hex numbers handled yet */
 case 's'   :
 break; 
 case 'c' :
 break;
 /* if it is not any expected char,
  * write it out and go on
  */
 default:   
 DrawChar(*s);
 convchar = True;
 } 
 } while (not convchar);
 break;
 case '\n' :/* newline ('\n') in control string */
 GetPen(&pt);  /* find current pen position */
 if (pt.v+linesz > wb-wt)   /* if it goes off , */
 { /* scroll the window */
 updrgn = NewRgn();
 ScrollRect(&(pw->portRect),0,-linesz,updrgn);
 DisposeRgn(updrgn);  /* no update */
 Move(0,-linesz);/* move onto window */
 }
 Move(-pt.h,linesz);/* move to next line */  break;
 default :/* any other character gets */
 DrawChar(*s); /*  written on the window */
 }
 s++;   /* move pointer to next char */
 } /*  in control string and cont*/
 SetPort(oldport); /* restore orignal graf port */
}

/* Convert numbers to ascii strings
 * Handles signed and unsigned
 * short and long values
 * Note:Length of string returned 
 * must be large enough to 
 * hold -2G (12 bytes)
 */
ntoa(n,len,issigned,s)
 ulong  n;/* number to convert */
 short  len;/* size of n (2 or 4)*/
 short  issigned;/* signed flag */
 char   *s; /* string to return */
{
 char   ts[12];  /* temporary string */
 int    i = 0;   /* counter, initialized */
 ulong  m;/* working copy of */
 long   sm; /* to convert signed values */
 
 if (n equals 0) /* if n is zero, place '0' */
 ts[i++] = '0';  /*  in temporary string */
 else
 {
 if (issigned)   /* if sign flag is set, */
 { /*  convert to signed value */
 if (len equals sizeof(long))
 sm = (long)n;
 else
 sm = (short)n;
 if (issigned = sm < 0) /* Check if value is */
 n = -sm; /*  negative. If so, */
 } /*  keep the flag and */
 /*  get the absolute value */
 while (n)/* Convert number into ascii */
 { /*  by repeatedly taking mod */
 ts[i++] = n % 10 + '0';  /*  and dividing.  */
 n /= 10; /*  This gives a string in */
 } /*  reverse order */
 if (issigned)   /* If number was negative, */
 ts[i++] = '-';  /*  stick a minus sign in */
 } /*  the string.*/
 
 do{    /* Reverse the string */
 *s++ = ts[--i]; /*  to the correct direction*/
 } 
 while (i);

 *s = '\0'; /* Place null terminator on */
}/*  string */
 
AAPL
$524.94
Apple Inc.
+5.93
MSFT
$40.01
Microsoft Corpora
-0.39
GOOG
$536.10
Google Inc.
-20.44

MacTech Search:
Community Search:

Software Updates via MacUpdate

Tweetbot 1.5.1 - Popular iOS twitter cli...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Mac DVDRipper Pro 4.1.7 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
PDFpenPro 6.2 - Advanced PDF toolkit for...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.2 - Edit and annotate PDFs with...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
Monolingual 1.5.9 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. It requires a 64-bit capable Intel-based Mac and at least... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
MYStuff Pro 2.0.16 - Create inventories...
MYStuff Pro is the most flexible way to create detail-rich inventories for your home or small business. Add items to MYStuff by dragging and dropping existing information, uploading new images, or... Read more

Latest Forum Discussions

See All

Have a Special Dead Trigger 2 Easter Bas...
Have a Special Dead Trigger 2 Easter Basket Full of Goodies, Courtesy of Madfinger Games Posted by Rob Rich on April 18th, 2014 [ permalink ] Dead Trigger 2 | Read more »
Zynga Launches Brand New Farmville Exper...
Zynga Launches Brand New Farmville Experience with Farmville 2: Country Escape Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
David. Review
David. Review By Cata Modorcea on April 18th, 2014 Our Rating: :: MINIMALISTIC IN A DIFFERENT WAYUniversal App - Designed for iPhone and iPad David is a minimalistic game wrapped inside of a soothing atmosphere in which the hero... | Read more »
Eyefi Unveils New Eyefi Cloud Service Th...
Eyefi Unveils New Eyefi Cloud Service That Allows Users to Share Media Across Personal Devices Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
Tales from the Dragon Mountain: The Lair...
Tales from the Dragon Mountain: The Lair Review By Jennifer Allen on April 18th, 2014 Our Rating: :: STEADY ADVENTURINGiPad Only App - Designed for the iPad Treading a safe path, Tales from the Dragon Mountain: The Lair is a... | Read more »
Yahoo Updates Flickr App with Advanced E...
Yahoo Updates Flickr App with Advanced Editing Features and More Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
My Incredible Body - A Kid's App to...
My Incredible Body - A Kid's App to Learn about the Human Body 1.1.00 Device: iOS Universal Category: Education Price: $2.99, Version: 1.1.00 (iTunes) Description: Wouldn’t it be cool to look inside yourself and see what was going on... | Read more »
Trials Frontier Review
Trials Frontier Review By Carter Dotson on April 18th, 2014 Our Rating: :: A ROUGH LANDINGUniversal App - Designed for iPhone and iPad Trials Frontier finally brings the famed stunt racing franchise to mobile, but how much does its... | Read more »
Evernote Business Notebook by Moleskin I...
Evernote Business Notebook by Moleskin Introduced – Support Available in Evernote for iOS Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
Sparkle Unleashed Review
Sparkle Unleashed Review By Jennifer Allen on April 18th, 2014 Our Rating: :: CLASSY MARBLE FLINGINGUniversal App - Designed for iPhone and iPad It’s a concept we’ve seen before, but Sparkle Unleashed is a solidly enjoyable orb... | Read more »

Price Scanner via MacPrices.net

iMacs on sale for up to $160 off MSRP this we...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
iPad Airs on sale this weekend for up to $100...
Best Buy has WiFi iPad Airs on sale for $50 off MSRP and WiFi + Cellular iPad Airs on sale for $100 off MSRP on their online store for a limited time, with prices now starting at $449. Choose free... Read more
Apple restocks refurbished Mac minis starting...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more
Hyundai Brings Apple CarPlay To The 2015 Sona...
Hyundai Motor America has announced it will bring Apple CarPlay functionality to the 2015 Sonata. CarPlay is pitched as a smarter, safer and easier way to use iPhone in the car and gives iPhone users... Read more
Updated iPads Coming Sooner Than We Had Thoug...
MacRumors, cites KGI securities analyst Ming Chi Kuo, well-respected as an Apple product prognisticator, saying that Apple will introduce an upgraded iPad Air and iPad mini in 2014/Q3, meaning the... Read more
Toshiba Unveils New High And Low End Laptop M...
Toshiba has announced new laptop models covering both the high-end and low-end of the notebook computer spectrum. Toshiba 4K Ultra HD Laptop Toshiba’s new Satellite P55t features one of the world’s... Read more
Save up to $270 with Apple refurbished 13-inc...
The Apple Store has Apple Certified Refurbished October 2013 13″ Retina MacBook Pros available starting at $1099, with models up to $270 off MSRP. Apple’s one-year warranty is standard, and shipping... Read more
Apple now offering refurbished iPad mini with...
The Apple Store has Certified Refurbished 2nd generation iPad minis with Retina Displays now available starting at $339. Apple’s one-year warranty is included with each model, and shipping is free.... Read more
Microsoft Blinks – Drops Microsoft Office 365...
Microsoft has dropped the annual subscription fee for Microsoft Office 365 Personal – which is needed in order to create and edit documents in Microsoft Office for iPad. However, Apple’s iOS and OS X... Read more
New AVG Vault Apps for iOS and Android Help K...
AVG Technologies N.V. an online security company for 177 million active users, has announced the launch of its latest mobile application, AVG Vault. The free app introduces an innovative user... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Retail - Manager - Holyoke - Apple I...
Job Summary Keeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you’re a master of them all. In the store’s fast-paced, Read more
*Apple* Retail - Manager - Apple (United Sta...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Retail - Market Leader - Cincinnati...
…challenges of developing individuals, building teams, and affecting growth across Apple Stores. You demonstrate successful leadership ability - focusing on excellence Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.