getting users' tty # into a C program
John Mount
mount at hpcupt1.HP.COM
Tue Mar 7 07:26:04 AEST 1989
>/ hpcupt1:comp.lang.c / davek at lakesys.UUCP (Dave Kraft) / 3:15 pm Mar 5, 1989 /
>In article <9794 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn ) writes:
>> In article <441 at lakesys.UUCP> davek at 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 <stdio.h>
extern char *ttyname();
main()
{
char *name;
name=ttyname(0);
printf("%s\n", name);
return(0);
}
John
More information about the Comp.lang.c
mailing list