Multi head/multi window hello world

I am trying to write a large X app. I have successfully modified my xorg.conf to setup 4 monitors on an NVIDIA Quatro5200. I am trying to modify a simple hello world application to open a window on three of the four monitors. depending on the changes to loop the window creation section and event handler portion, i get either a Bus Error, Segmentation Fault, or a BadMatch. (Not sure where the BadMatch is coming from) Here is the code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>

int main (int argc, char *argv[])
{
    Display                 *display;
    Visual                  *visual[3];
    int                     depth[3];
    int                     text_x;
    int                     text_y;
    XSetWindowAttributes    frame_attributes[3];
    int                     screen_num;
    int                     screen_ind, i;
    unsigned int            display_width[3], display_height[3];
    Window                  frame_window[3];
    XFontStruct             *fontinfo = NULL;
    XGCValues               gr_values;
    GC                      graphical_context;
    XKeyEvent               event;
    char                    hello_string[] = "Hello X";
    int                     hello_string_length=strlen(hello_string);

    display = XOpenDisplay(NULL);

  for( i = 0; i < 3; i++ )
  {
    screen_num = i+1;
    visual = DefaultVisual(display, screen_num);
    depth  = DefaultDepth(display, screen_num);
    display_width  = DisplayWidth(display, screen_num);
    display_height = DisplayHeight(display, screen_num);

    frame_attributes.background_pixel = XBlackPixel(display, screen_num);
    frame_attributes.override_redirect = 1;

    /* create the application window */
    frame_window = XCreateWindow(display, XRootWindow(display, screen_num),
                                 0, 0, display_width, display_height, 0, depth,
                                 InputOutput, visual, CWBackPixel|CWOverrideRedirect,
                                 &frame_attributes);
                                                                                                                  
    XSelectInput(display, frame_window, ExposureMask );

    if( fontinfo == NULL )
    {
      fontinfo = XLoadQueryFont(display, "10x20");

      if(fontinfo != NULL )
      {
        gr_values.font = fontinfo->fid;
        gr_values.foreground = XWhitePixel(display, screen_num);
        graphical_context = XCreateGC(display, frame_window,
                                      GCFont+GCForeground, &gr_values);
      }
    }

    XMapWindow(display, frame_window);
  }

    while ( 1 ) {
fprintf(stdout, "1\n");
fflush(stdout);

        XNextEvent(display, (XEvent *)&event);

        switch ( event.type ) {
            case Expose:
            {
                XWindowAttributes window_attributes;
                int font_direction, font_ascent, font_descent;
                XCharStruct text_structure;

                if( event.window == frame_window[0] )
                {
                  hello_string[6] = '1';
                  screen_ind = 0;
                }
                else if( event.window == frame_window[1] )
                {
                  hello_string[6] = '2';
                  screen_ind = 1;
                }
                else if( event.window == frame_window[2] )
                {
                  hello_string[6] = '3';
                  screen_ind = 2;
                }
                else
                {
                  printf("event.window = %d\n", (int)event.window );
                  return(0);
                }
fprintf(stdout, "2\n");
fflush(stdout);

                XTextExtents(fontinfo, hello_string, hello_string_length,
                             &font_direction, &font_ascent, &font_descent,
                             &text_structure);
fprintf(stdout, "3\n");
fflush(stdout);
                XGetWindowAttributes(display, frame_window[screen_ind], &window_attributes);
fprintf(stdout, "4\n");
fflush(stdout);
                text_x = (window_attributes.width - text_structure.width)/2;
                text_y = (window_attributes.height -
                          (text_structure.ascent+text_structure.descent))/2;
fprintf(stdout, "5\n");
fflush(stdout);
                XDrawString(display, frame_window[screen_ind], graphical_context, text_x, text_y, hello_string, hello_string_length);
fprintf(stdout, "6\n");
fflush(stdout);
                break;
            }
            default:
                break;
        }
    }
    return(0);
}

If I loop the fontinfo and graphical context portion like the rest, I get a Bus Error.

I can run the single version on each of the different screens one at a time, just not all three in one program.

Help!

Just asking as i dont speak C[#/+].
0) Is this a GUI or console app?
1) It (to me) looks like you can only adress one screen at the time, due to the if-elif block, you might want to change (or just add) a for ARG loop?

hth

I would say it is a console ap. I need to drive three displays that are nowhere near the systems "console." I decided to force the different heads into specific screens so I do not have to worry about resize events on the main console. That is why I am trying to determine which window the event came from. Just trying to say "hello 1" on the first display and "Hello 2" on the second, etc. I will be taking over the entire display. No real windows/GUI code. Mostly text overlays and blending images.