Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ttrdc.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!dual!qantel!ihnp4!mgnetp!ltuxa!ttrdc!levy From: levy@ttrdc.UUCP (Daniel R. Levy) Newsgroups: net.lang.c Subject: Re: What is wrong with this program? Message-ID: <353@ttrdc.UUCP> Date: Sat, 10-Aug-85 16:31:19 EDT Article-I.D.: ttrdc.353 Posted: Sat Aug 10 16:31:19 1985 Date-Received: Wed, 14-Aug-85 07:51:14 EDT References: <117@graffiti.UUCP> Distribution: net Organization: AT&T, Computer Systems Division, Skokie, IL Lines: 32 bruce@graffiti.UUCP (Bruce Jilek) <117@graffiti.UUCP>: > >Why does printf insist that data->ut_line is a null string while >putchar can display all of the characters of this array? >... > struct utmp { /* This structure is straight out of utmp.h */ > char ut_line[8]; /* tty name */ > char ut_name[8]; /* user id */ > long ut_time; /* time on */ > }; >... > 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); >... printf expects strings which are null-terminated at the end. There is no guarantee that what you get in the arrays in struct utmp will be this way. Ergo, strange results. Putchar is the way to go unless you want to copy the data out of the struct utmp into something which is null terminated for the sake of printf. -- ------------------------------- Disclaimer: The views contained herein are | dan levy | yvel nad | my own and are not at all those of my em- | an engihacker @ | ployer, my pets, my plants, my boss, or the | at&t computer systems division | s.a. of any computer upon which I may hack. | skokie, illinois | | "go for it" | Path: ..!ihnp4!ttrdc!levy -------------------------------- or: ..!ihnp4!iheds!ttbcad!levy