From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 30 21:02:39 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 86749106564A for ; Tue, 30 Jun 2009 21:02:39 +0000 (UTC) (envelope-from rick@kiwi-computer.com) Received: from hamlet.setfilepointer.com (hamlet.SetFilePointer.com [63.224.10.2]) by mx1.freebsd.org (Postfix) with SMTP id 2FB7E8FC14 for ; Tue, 30 Jun 2009 21:02:39 +0000 (UTC) (envelope-from rick@kiwi-computer.com) Received: (qmail 25677 invoked from network); 30 Jun 2009 16:02:38 -0500 Received: from keira.kiwi-computer.com (HELO kiwi-computer.com) (63.224.10.3) by hamlet.setfilepointer.com with SMTP; 30 Jun 2009 16:02:38 -0500 Received: (qmail 34031 invoked by uid 2001); 30 Jun 2009 21:02:38 -0000 Date: Tue, 30 Jun 2009 16:02:38 -0500 From: "Rick C. Petty" To: Alexander Best Message-ID: <20090630210238.GA33849@keira.kiwi-computer.com> References: <20090630181121.GA32665@keira.kiwi-computer.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Cc: freebsd-hackers@freebsd.org Subject: Re: c question: *printf'ing arrays X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: rick-freebsd2008@kiwi-computer.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2009 21:02:39 -0000 On Tue, Jun 30, 2009 at 08:21:03PM +0200, Alexander Best wrote: > thanks. now the output gets redirected using >. i'm quite new to programming > under unix. sorry for the inconvenience. No problem; we all had to learn sometime. But what I suggested should work for every platform that adheres to POSIX. If you were using fprintf/fwrite, then it would work on anything that's standard C. As for redirection, windows command line allows the same type of redirection. > so i guess there is no really easy way to output an inhomogeneous struct to > stdout without using a loop to output each array contained in the struct. That's not something C would ever provide easily. You may want to use a different high-level language. However, I often use macros for printing pieces of structures, for example I used this to print out sizes of kernel structures: #define SIZE(astruct, member) \ printf("%d\t\t.%s\n", sizeof(astruct.member), #member) #include ... struct ktr_header header; struct ktr_genio genio; printf("%d\tktr_header:\n", sizeof(header)); SIZE(header, ktr_len); SIZE(header, ktr_type); SIZE(header, ktr_pid); SIZE(header, ktr_comm); SIZE(header, ktr_time); SIZE(header, ktr_time.tv_sec); SIZE(header, ktr_time.tv_sec); SIZE(header, ktr_tid); printf("\n%d\tktr_genio:\n", sizeof(genio)); SIZE(genio, ktr_fd); SIZE(genio, ktr_rw); In your case, you could make a macro for each type. Without an example of how you want the output to look, it's hard for us to show you code that will produce such output. -- Rick C. Petty