Ok this works for me if I do the following …
- Your printf statement
printf( “[%c|%d]” );
MINE:
printf( “[%c|%d]\n”, chIn, chIn );
I found that the output does not do directly out unless you
- Add a \n
or
- write( STDOUT_FILENO, str, strlen( str ) );
Complete Text to my program… works for me… Started with your base
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/time.h>
#include <pthread.h>
#include <sys/neutrino.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/termio.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/uio.h>
struct termios saved_attributes;
bool SetupTerminal()
{
struct termios tattr;
// char *name;
/* Make sure stdin is a terminal. */
if (!isatty (STDIN_FILENO)){
fprintf (stderr, “Not a terminal.\n”);
exit (EXIT_FAILURE);
}
/* Save the terminal attributes so we can restore them later. */
tcgetattr (STDIN_FILENO, &saved_attributes);
/* Set the funny terminal modes. /
tcgetattr (STDIN_FILENO, &tattr);
tattr.c_lflag &= ~(ICANON|ECHO); / Clear ICANON and ECHO. */
tattr.c_cc[VMIN] = 1;
tattr.c_cc[VTIME] = 0;
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
return true;
}
int main(void* argc, void* argv[] )
{
SetupTerminal();
char chIn;
for(;
{
read (STDIN_FILENO, &chIn, 1);
printf( “[%c|%d]\n”, chIn, chIn );
}
// atexit (saved_attributes);
return 0;
}
“Fred” <fprog@nowhere.users.sourceforge.net> wrote in message
news:971sk9$5oj$1@inn.qnx.com…
#include <stdio.h
#include <string.h
#include <unistd.h
#include <stdlib.h
#include <fcntl.h
#include <sys/time.h
#include <pthread.h
#include <sys/neutrino.h
#include <stdio.h
#include <string.h
#include <errno.h
#include <unistd.h
#include <stdlib.h
#include <fcntl.h
#include <sys/time.h
#include <sys/termio.h
#include <sys/stat.h
#include <sys/select.h
#include <sys/ioctl.h
#include <sys/types.h
#include <sys/uio.h
struct termios saved_attributes;
bool SetupTerminal()
{
struct termios tattr;
// char *name;
/* Make sure stdin is a terminal. */
if (!isatty (STDIN_FILENO)){
fprintf (stderr, “Not a terminal.\n”);
exit (EXIT_FAILURE);
}
/* Save the terminal attributes so we can restore them later. */
tcgetattr (STDIN_FILENO, &saved_attributes);
/* Set the funny terminal modes. /
tcgetattr (STDIN_FILENO, &tattr);
tattr.c_lflag &= ~(ICANON|ECHO); / Clear ICANON and ECHO. */
tattr.c_cc[VMIN] = 1;
tattr.c_cc[VTIME] = 0;
tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
return true;
}
int main()
{
SetupTerminal();
char chIn;
for(;
{
read (STDIN_FILENO, &chIn, 1);
printf( “[%c|%d]” );
}
// atexit (saved_attributes);
return 0;
}
This doesn’t work at all, neither.
In fact, it does nothing even ,
only CTRL-C works.
Do you have to full working code ?
Fred.