Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site bunker.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ittatc!bunker!wtm From: wtm@bunker.UUCP (William T. McGarry) Newsgroups: net.lang.c Subject: Re: What is wrong with this program Message-ID: <924@bunker.UUCP> Date: Tue, 13-Aug-85 00:43:02 EDT Article-I.D.: bunker.924 Posted: Tue Aug 13 00:43:02 1985 Date-Received: Sun, 18-Aug-85 01:01:33 EDT Distribution: net Organization: Bunker Ramo, Trumbull Ct Lines: 42 < Why does printf insist that data->ut_line is a null string while < putchar can display all of the characters of this array? < < Sorry if this is a trivial question, but it beats the hell < out of me. The problem with this program is the way in which "data" is defined and used: struct utmp *data; This only defines that "data" is to be a pointer to a structure with the format of "utmp". It does not allocate any space for the structure itself. You have to either: 1. Do a malloc right after the open the file - data = (struct utmp *) malloc(sizeof(struct utmp)); 2. Since "utmp" is such a small structure, a malloc is problably not even needed. Instead, write it like this: struct utmp data; which does allocate space for the structure. In this case, the "fread" call should read into "&data" rather than "data" and all of the lines such as "data->ut_line" should be changed to "data.ut_line" and change all of the lines from "utmp->ut_line" to "utmp.ut_line" and the "fread" call should read into "&data". Both of these methods work fine on my Fortune 32:16. Hope this helps! Bill McGarry decvax!ittatc!bunker!wtm