fyplinux
September 20th, 2007, 10:06 PM
Hi,
I am currently learning to program with the X11 lib, I met a problem that the printf function couldn't work until X11 is broken.
below is the code
================================
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
Display *d; int s; Window w; XEvent ev;
int should_quit = 0;
d = XOpenDisplay(NULL);
s = XDefaultScreen(d);
w = XCreateSimpleWindow(d, XRootWindow(d, s), 0, 0,
200, 200, 0,
XBlackPixel(d, s),
XWhitePixel(d, s));
XSelectInput(d, w, ButtonPressMask);
XMapWindow(d, w);
printf("dfdfdsfs");/*printf is called here*/
while(!should_quit)
{
XNextEvent(d, &ev);
switch(ev.type)
{
case ButtonPress:
should_quit = 1;
break;
default:
break;
}
}
return 0;
}
when I closed the window, the output of the terminal was
=============================
X connection to :0.0 broken (explicit kill or server shutdown).
dfdfdsfs
But, if the printf call is coded like:
printf("dfdfdsfs\n");
the program works properly, here is the output
==============================
dfdfdsfs
X connection to :0.0 broken (explicit kill or server shutdown).
The question is why printf cannot work properly without the newline endian?
thanks.
I am currently learning to program with the X11 lib, I met a problem that the printf function couldn't work until X11 is broken.
below is the code
================================
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
Display *d; int s; Window w; XEvent ev;
int should_quit = 0;
d = XOpenDisplay(NULL);
s = XDefaultScreen(d);
w = XCreateSimpleWindow(d, XRootWindow(d, s), 0, 0,
200, 200, 0,
XBlackPixel(d, s),
XWhitePixel(d, s));
XSelectInput(d, w, ButtonPressMask);
XMapWindow(d, w);
printf("dfdfdsfs");/*printf is called here*/
while(!should_quit)
{
XNextEvent(d, &ev);
switch(ev.type)
{
case ButtonPress:
should_quit = 1;
break;
default:
break;
}
}
return 0;
}
when I closed the window, the output of the terminal was
=============================
X connection to :0.0 broken (explicit kill or server shutdown).
dfdfdsfs
But, if the printf call is coded like:
printf("dfdfdsfs\n");
the program works properly, here is the output
==============================
dfdfdsfs
X connection to :0.0 broken (explicit kill or server shutdown).
The question is why printf cannot work properly without the newline endian?
thanks.