Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site grkermi.UUCP Path: utzoo!linus!decvax!genrad!grkermi!andrew From: andrew@grkermi.UUCP (Andrew W. Rogers) Newsgroups: net.lang.c Subject: Re: What is wrong with this program? Message-ID: <545@grkermi.UUCP> Date: Sat, 10-Aug-85 08:57:55 EDT Article-I.D.: grkermi.545 Posted: Sat Aug 10 08:57:55 1985 Date-Received: Mon, 12-Aug-85 20:54:39 EDT References: <117@graffiti.UUCP> Reply-To: andrew@grkermi.UUCP (Andrew W. Rogers) Distribution: net Organization: GenRad, Inc., Concord, Mass. Lines: 28 Summary: In article <117@graffiti.UUCP> bruce@graffiti.UUCP (Bruce Jilek) writes: >Why does printf insist that data->ut_line is a null string while >putchar can display all of the characters of this array? > > char ut_line[8]; /* tty name */ > ... > for (i = 0; i <= 7; i++) { > putchar(data->ut_line[i]); > printf("\n"); > printf("%s %s %ld\n", data->ut_name, > data->ut_line, data->ut_time); > ... > >Sample output: > > tty03 /* This shows that data->ut_line isn't null */ >bruce (null) 492299400 /* So what's the problem in this line? */ Are you *sure* it really isn't null? If the first character were \0, your 'putchar' loop would give no indication of that fact; the \0 would be invisible and the remaining characters would print normally. Of course, 'printf' would consider the string null. Try replacing the 'putchar...' with 'printf("\\%03o ", data->ut_line[i]);' and see what the characters in the string *really* are. Either that, or redirect the output to a file and get a binary/octal/hex dump of it. AWR