Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpcupt1!mount From: mount@hpcupt1.HP.COM (John Mount) Newsgroups: comp.lang.c Subject: Re: getting users' tty # into a C program Message-ID: <5940005@hpcupt1.HP.COM> Date: 6 Mar 89 21:26:04 GMT References: <441@lakesys.UUCP> Organization: Hewlett Packard, Cupertino Lines: 42 >/ hpcupt1:comp.lang.c / davek@lakesys.UUCP (Dave Kraft) / 3:15 pm Mar 5, 1989 / >In article <9794@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn ) writes: >> In article <441@lakesys.UUCP> davek@lakesys.UUCP (Dave Kraft) writes: >> >I am writing a C program that need a user's tty number (i.e. tty3A). Is there >> >any internal/external function that can accomplish this? >> >> Most UNIX systems have a ttyname() library function for doing this. >> It doesn't work perfectly... > > >Here's what I tried: > >main() >{ > char *name; > > *name=ttyname(); > printf("%s\n", *name); >} > >(Plus I grepped around in all of the include files for ttyname, and I couldn't >find it) Is there anything I'm doing wrong in the above program?? >Thanks in advance. >Dave > Read up! ttyname needs a file descriptor as an argument and you shouldn't be dereferencing name when you use it. The following works on an Hp9000/360 running HPUX6.02: #include extern char *ttyname(); main() { char *name; name=ttyname(0); printf("%s\n", name); return(0); } John