What is wrong with this program?

Bruce Jilek bruce at graffiti.UUCP
Thu Aug 8 14:28:19 AEST 1985


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.  (If it helps, this is on a Fortune 32:16 - sort of v7.)


/****************************************************************
    This program is a rough imitation of "who /usr/adm/wtmp".
****************************************************************/
#include <stdio.h>

main()
{

	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 */
	};

	FILE *f;
	int i;
	struct utmp *data;
	if (f = fopen ("/usr/adm/wtmp", "r")) {
		while ((fread (data, sizeof(struct utmp), 1, f))  >  0) {
			putchar('\t');
			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);
		}
		fclose(f);
	}
}

/**********************************************************************
  End of program
**********************************************************************/

Sample output:
	
	tty03                 /*  This shows that data->ut_line isn't null */
bruce	(null)	492299400     /*  So what's the problem in this line?      */
	tty03
	(null)	492299405
	tty02
mike	(null)	492299409
        .
        .
        .



More information about the Comp.lang.c mailing list