12-15-2004 05:33 AM
Q1. Are these only available with C++ and not the standard Ansi C (HP-UX 11.0)?
Q2. Since I am forced to use getch when reading an input file, I have run into a problem where control characters are not read in, i.e. ^A, etc.
Anyone have a workaround? Escape characters do not appear to work, i.e. \^A.
Solved! Go to Solution.
12-15-2004 06:30 AM
The following code will loop until you press 'q':
int cinitscr(void) /* returns TRUE if ok */
int h = FALSE;
h = (stdscr != NULL);
} /* cinitscr */
int ch = 0;
while (ch != 'q')
(void) printw("Enter char: ");
ch = getch();
if (ch >= ' ' && ch <= '~') (void) printw("%c",(char) ch);
else (void) printw(" ");
(void) printw(" %4o\n",ch);
compile/link like this:
cc key.c -lcurses -o key
If I got all that typed in without any boo-boos it should work just as claimed.
Oh, and no, ANSI C don't know nothing about them C++ constructs like streams.
12-15-2004 09:46 AM
Clay, some additional information-
Purpose is to read in an array to the program that will be using this array to pass a buffer via a tcp socket program to a mainframe CICS application. Unfortunately, this buffer must be interpreted from the acii characters it receives in the buffer.
With that in mind, I don't believe the key characters would be viable, unless I am missing something.
12-15-2004 01:28 PM
12-16-2004 04:23 AM
Will give it a shot, report results, assign points. Thanks for clarification.
Incidentally, I would much rather have used getline() since the file I will read from has a number of parms I want included in the socket program. I was forced to use getch() due to the lack of appropriate header files.
This is not a life or death production issue.
The socket program is my emulation of scenarios where it performs as a banking institution, POS contoller, etc. and used for testing against the CICS socket programs.
Always appreciate your input and posts.
12-16-2004 06:00 AM
file. Why are you "forced to use getch"?
getch doesn't even read from a file, it reads
from the terminal! Perhaps you actually
want getc or getchar, or even scanf.
What is getline()? It does not appear
to be a part of the standard C library.
In C the usual way to read til EOL is
12-16-2004 06:19 AM
Gregory is correct.
Here is a snippet of my problem:
Below is how I read the input file-
output[i] = fgetc(input_file);
This is the data I want to read in-
This is what I get-
As you can see, I lose the ^A, ^D, ^N.
If I hard code in the unix socket program, the buffer is passed correctly to the mainframe CICS socket program.
If I read the data into the unix socket program, the buffer passed to CICS is minus any ^A, etc.
Sorry for not stating this correctly in the beginning.
12-16-2004 09:05 AM
#define assign_errno(x) ((errno != 0) ? errno : (x))
static void problem(char *msg, int err)
(void) fprintf(stderr,"%s (%d)\n",msg,err);
} /* problem */
#define STDOUT_FDES 1
int main(int argc, char *argv)
int cc = 0;
if (argc > 0)
char *in_fname = NULL,s_err;
int in_fdes = -1;
in_fname = argv;
in_fdes = open(in_fname,O_RDONLY,0400);
if (in_fdes >= 0)
int n = 0;
unsigned char b;
n = read(in_fdes,(void *) b,sizeof(b));
if (n > 0)
/* your stuff goes here */
/* send n bytes stored in b */
/* I'll just write on stdout */
(void) write(STDOUT_FDES,(void *) b,(size_t) n);
if (n < 0)
cc = assign_errno(-2);
while ((n == sizeof(b)) && (cc == 0));
cc = assign_errno(-1);
(void) sprintf(s_err,"Can't open file '%s'",in_fname);
cc = 254;
problem("No input file",cc);
} /* main */
Compile like this:
cc tester.c -o tester
As a test: tester tester will read in the source and output it to stdout, if I got all this typed in correctly.
That should do it. Where I'm doing the write() is where you will probably put your send() after setting up the socket.
12-16-2004 11:09 AM
Danged if that didn't work!!!!!!!
Thanks for all the time spent on this.