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
$103.37
Apple Inc.
+0.90
MSFT
$44.68
Microsoft Corpora
-0.21
GOOG
$536.25
Google Inc.
+9.71

MacTech Search:
Community Search:

Software Updates via MacUpdate

Apple Security Update 2014-005 - For OS...
Apple Security Update is recommended for all users and improves the security of Mac OS X. For information on the security content of this update, please visit this website: http://support.apple.com/... Read more
EyeTV 3.6.6 - Watch and record TV on you...
EyeTV brings a rich TV experience to your Mac. Watch live TV on your Mac. Pause, rewind, and record whenever you want. EyeTV gives you powerful control over what you watch and how you watch it. Put... Read more
RapidWeaver 6.0 - Create template-based...
RapidWeaver is a next-generation Web design application to help you easily create professional-looking Web sites in minutes. No knowledge of complex code is required, RapidWeaver will take care of... Read more
NTFS 12.0.39 - Provides full read and wr...
Paragon NTFS breaks down the barriers between Windows and OS X. Paragon NTFS effectively solves the communication problems between the Mac system and NTFS, providing full read and write access to... Read more
RestoreMeNot 2.0.3 - Disable window rest...
RestoreMeNot provides a simple way to disable the window restoration for individual applications so that you can fine-tune this behavior to suit your needs. Please note that RestoreMeNot is designed... Read more
Macgo Blu-ray Player 2.10.9.1750 - Blu-r...
Macgo Mac Blu-ray Player can bring you the most unforgettable Blu-ray experience on your Mac. Overview Macgo Mac Blu-ray Player can satisfy just about every need you could possibly have in a Blu-ray... Read more
Apple iOS 8.1 - The latest version of Ap...
The latest version of iOS can be downloaded through iTunes. Apple iOS 8 comes with big updates to apps you use every day, like Messages and Photos. A whole new way to share content with your family.... Read more
TechTool Pro 7.0.5 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PDFKey Pro 4.0.2 - Edit and print passwo...
PDFKey Pro can unlock PDF documents protected for printing and copying when you've forgotten your password. It can now also protect your PDF files with a password to prevent unauthorized access and/... Read more
Yasu 2.9.1 - System maintenance app; per...
Yasu was originally created with System Administrators who service large groups of workstations in mind, Yasu (Yet Another System Utility) was made to do a specific group of maintenance tasks... Read more

Latest Forum Discussions

See All

The Silent Age Episode 2 Review
The Silent Age Episode 2 Review By Jennifer Allen on October 22nd, 2014 Our Rating: :: ROUNDING THINGS OFF NICELYUniversal App - Designed for iPhone and iPad Rounding off a great point and click adventure comes The Silent Age... | Read more »
Craft Your Own Mini-Games with Papercade
Craft Your Own Mini-Games with Papercade Posted by Jessica Fisher on October 22nd, 2014 [ permalink ] iPad Only App - Designed for the iPad Scrapbookers move over, Scrapgaming is the new thing. | Read more »
Reshape Review
Reshape Review By Jennifer Allen on October 22nd, 2014 Our Rating: :: SIMPLE SHAPESUniversal App - Designed for iPhone and iPad Match triangles together to form cubes in this fast-paced and twitchy game.   | Read more »
Miika (Games)
Miika 1.0.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.0 (iTunes) Description: Miika is a beautiful 3D puzzle game based on camera perspectives combined with the use of optical illusions. Miika challenges... | Read more »
Infuse Pro (Photography)
Infuse Pro 3.0 Device: iOS Universal Category: Photography Price: $9.99, Version: 3.0 (iTunes) Description: ** All-new version 3 includes fully licensed and certified DTS® and DTS-HD® audio! ** | Read more »
Swap Heroes (Games)
Swap Heroes 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: **Half price for a limited time only** Swap Heroes is a casual turn-based strategy adventure. Form a group of heroes and guide them... | Read more »
Ghost Blade (Games)
Ghost Blade 1.1 Device: iOS Universal Category: Games Price: $4.99, Version: 1.1 (iTunes) Description: Get the most outstanding 3D Action Game from App Store NOW! For those who dare pursue dreams. Masterpiece of Yu Shi Game ---China... | Read more »
Fiete – A Day on a Farm Review
Fiete – A Day on a Farm Review By Amy Solomon on October 21st, 2014 Our Rating: :: A MEMORABLE EXPERIENCEUniversal App - Designed for iPhone and iPad Fiete – A day on a farm in an interactive app for young children full of... | Read more »
Tilt to Live: Gauntlet’s Revenge is Almo...
Tilt to Live: Gauntlet’s Revenge is Almost Here Posted by Jessica Fisher on October 21st, 2014 [ permalink ] One Man Left has announced the official release date of Tilt to Live: Gauntlet’s Re | Read more »
Starfly Review
Starfly Review By Jennifer Allen on October 21st, 2014 Our Rating: :: CHANGE OF PACEiPad Only App - Designed for the iPad Want a slightly different browsing experience? Starfly is a pretty personalized one but it’s also buggy.   | Read more »

Price Scanner via MacPrices.net

AT&T accepting preorders for new iPads fo...
AT&T Wireless is accepting preorders for the new iPad Air 2 and iPad mini 3, cellular models, for $100 off MSRP with a 2-year service agreement: - 16GB iPad Air 2 WiFi + Cellular: $529.99 - 64GB... Read more
Apple offering refurbished Mac Pros for up to...
The Apple Store is offering Apple Certified Refurbished 2013 Mac Pros for up to $600 off the cost of new models. An Apple one-year warranty is included with each Mac Pro, and shipping is free. The... Read more
Select MacBook Airs $100 off MSRP, free shipp...
B&H Photo has 2014 a couple of MacBook Airs on sale for $100 off MSRP. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels Desktop and LoJack for... Read more
13-inch 2.5GHz MacBook Pro on sale for $100 o...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $999.99 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
Strong iPhone, Mac And App Store Sales Drive...
Apple on Monday announced financial results for its fiscal 2014 fourth quarter ended September 27, 2014. The Company posted quarterly revenue of $42.1 billion and quarterly net profit of $8.5 billion... Read more
Apple Posts How-To For OS X Recovery
OS X 10.7 Lion and later include OS X Recovery. This feature includes all of the tools you need to reinstall OS X, repair your disk, and even restore from a Time Machine backup. OS X Recovery... Read more
Mac OS X Versions (Builds) Supported By Vario...
Apple Support has posted a handy resource explaining which Mac OS X versions (builds) originally shipped with or are available for your computer via retail discs, downloads, or Software Update. Apple... Read more
Deals on 2011 13-inch MacBook Airs, from $649
Daily Steals has the Mid-2011 13″ 1.7GHz i5 MacBook Air (4GB/128GB) available for $699 with a 90 day warranty. The Mid-2011 13″ 1.7GHz i5 MacBook Air (4GB/128GB SSD) is available for $649 at Other... Read more
2013 15-inch 2.0GHz Retina MacBook Pro availa...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
Updated iPad Prices
We’ve updated our iPad Air Price Tracker and our iPad mini Price Tracker with the latest information on prices and availability from Apple and other resellers, including the new iPad Air 2 and the... Read more

Jobs Board

Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, 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
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.