First, tnx all;Rich,
I modified your code sample as follows:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include<gconio.h>
/******************************************************************/
int main (int argc, char *argv[])
{
FILE *mousefp;
int a[10];
int mousedata;
int knt;
int ev;
int aknt;
if((mousefp=fopen("/dev/input/mouse0", "rb")) == NULL)
{
printf("Error line:%d, could open directory\n", __LINE__);
exit(-1);
}
ev=0;
while(1){//outer
knt=0;
aknt=0;
while(1)//inner
{
printf("top-while\n");
mousedata=fgetc(mousefp);
//printf("%d;%X\n",knt,mousedata);knt=knt+1;
a[aknt]=mousedata;aknt=aknt+1;knt=knt+1;
fflush(stdout);
printf("bottom-while\n");
if(knt>5){knt=0;break;}
}//inner
printf("event:%X\n",ev);ev=ev+1;
printf("a[0]=%d;a[1]=%d;a[2]=%d;a[3]=%d;a[4]=%d;a[5]=%d\n",a[0],a[1],a[2],a[3],a[4],a[5]);
}//outer
return(0);
}
/******************************************************************/
The output of this clearly demonstrates that the inner while(your while) is executing six times
bfore falling through to the outer loop! What is even more amazing to me is that the following
code exhibits the same behaviour with a different executable than the printf:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include<gconio.h>
/******************************************************************/
int main (int argc, char *argv[])
{
FILE *mousefp;
int a[10];
int mousedata;
int knt;
int ev;
int aknt;
if((mousefp=fopen("/dev/input/mouse0", "rb")) == NULL)
{
printf("Error line:%d, could open directory\n", __LINE__);
exit(-1);
}
ev=0;
while(1){//outer
knt=0;
aknt=0;
while(1)//inner
{
printf("top-while\n");
mousedata=fgetc(mousefp);
//printf("%d;%X\n",knt,mousedata);knt=knt+1;
a[aknt]=mousedata;aknt=aknt+1;knt=knt+1;
fflush(stdout);
printf("bottom-while\n");
if(knt>5){knt=0;break;}
}//inner
printf("event:%X\n",ev);ev=ev+1;
printf("a[0]=%d;a[1]=%d;a[2]=%d;a[3]=%d;a[4]=%d;a[5]=%d\n",a[0],a[1],a[2],a[3],a[4],a[5]);
}//outer
return(0);
}
/******************************************************************/
it looks like *any?* expression with 'mousedata' as the r-value will do this; which further implies
that the variable 'mousedata gets "commandeered" by the process engendered by 'mouse0';
further that any expression with 'mousedata' as the r-value is likewise "commandeered",
possibly by wrapping it in a temporary function-wrapper?
I can see how the variable could be directly written to by pointer from somwhere, but the miltiple execution involving it is, to me, *astounding!*!
I could not have *bought* what I have learned in the last 24 hours.
As for the other suggestions I will try them later, in about six hours. Again TNX all.