- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- C programming question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 11:07 PM
02-26-2004 11:07 PM
Does anyone know the C code to print the integer representation on the EOF character to standard out ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 11:34 PM
02-26-2004 11:34 PM
Re: C programming question
main () {
printf ("%d\n", VEOF) ;
}
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2004 11:37 PM
02-26-2004 11:37 PM
Re: C programming question
main(){
printf("%d\n",EOF);
}
However, you'll find this defined in the system "stdio.h" include file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 12:06 AM
02-27-2004 12:06 AM
Re: C programming question
What you need to do is do a gtty, get the EOF value from there and then print it like the previous replies, using a %d for printf.
So, first start reading the manual page stty(2), stty(7), termio(7). I don't have time now to create the program, perhaps later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 12:33 AM
02-27-2004 12:33 AM
Re: C programming question
Many thanks for the answers. I didn't know how simple the solution was - the key being the C library.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 02:09 AM
02-27-2004 02:09 AM
SolutionYou have to ask the process itself (actually the controlling terminal's port). The EOF value can actually change "on the fly". The 'trick' is to do an ioctl on stdin requesting the termio structure be loaded. You then examine an array of "control characters" within this structure. VEOF refers refers to the array index that hold the EOF control character. VEOF is defined to be 4 and because by default the EOF is a Control-D (ASCII 4), Graham's solution works (most of the time) completely by accident.
------------------------------------------
Here's the proper method:
#include
#include
#define assign_errno(x) ((errno != 0) ? errno : (x))
extern int errno;
#define STDIN_FDES 0
int main()
{
int cc = 0;
struct termio t;
cc = ioctl(STDIN_FDES,TCGETA,&t);
if (cc == 0)
{
printf("%d\n",(int) t.c_cc[VEOF]);
}
else
{
cc = assign_errno(-1);
(void) fprintf(stderr,"Ioctl failed (%d)\n",cc);
}
return(cc);
}
-----------------------------------------
Incidently, you could add to this code by assigning a new value to t.c_cc[VEOF] and then doing an ioctl(STDIN_FDES,TCSETA,&t) and that would assign another character to the EOF function. This is what is done when you issue a stty command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 02:11 AM
02-27-2004 02:11 AM
Re: C programming question
Thanks for that information,Clay. That makes very interesting reading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 02:16 AM
02-27-2004 02:16 AM
Re: C programming question
Just call me Uriah Heep ...
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 02:41 AM
02-27-2004 02:41 AM
Re: C programming question
printf("%d\n",(int) t.c_cc[VEOF]);
should be:
(void) printf("%d\n",(int) t.c_cc[VEOF]);
because we are explicitly ignoring the result (the number of bytes transmitted) returned by the printf() function. Both versions work perfectly well; I'm just ultra nit-picky --- in all things except English grammar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 03:21 AM
02-27-2004 03:21 AM
Re: C programming question
After reading Elmars post, I tried exactly the same thing you mention here with the ioctl. For the life of me I could not get the thing to compile. cc_c was not a struct member. It plainy is though.
Any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 03:36 AM
02-27-2004 03:36 AM
Re: C programming question
#include
That actually includes
It should be t.c_cc[VEOF] NOT t.cc_c[VEOF]. In C, spelling counts much more than it does in English.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2004 03:42 AM
02-27-2004 03:42 AM
Re: C programming question
Good spot there A.Clay :)