From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 30 16:49:34 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 AFA721065674 for ; Tue, 30 Jun 2009 16:49:34 +0000 (UTC) (envelope-from tevans.uk@googlemail.com) Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com [209.85.219.213]) by mx1.freebsd.org (Postfix) with ESMTP id 3A10B8FC0C for ; Tue, 30 Jun 2009 16:49:33 +0000 (UTC) (envelope-from tevans.uk@googlemail.com) Received: by ewy9 with SMTP id 9so332484ewy.43 for ; Tue, 30 Jun 2009 09:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=fKHZB8mI3nabLrfSFwMm4z0iGvXRqqQHw2WKnX99hpM=; b=GGKSfVYvO0oWMLU3dp72uoRqGu0h//0k/ubyAG6IsxQIRFdExID2X+vRd25QIYCRyp 1yRWawTEdkplpz/BzfQxBb/3agBQXJ//zzdcNne9yRW/qIdlkdDhL+m3/vOpqU1guRxS B3IvnSd7u5yms5WKB2YFOnzFqMtJB38+jTMyg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=dj39sOmNfZMQm4tGGlBsGOJagkbkHoTfCagQDs88JWDBV+jmGsYPz/v3JbDLhUSmgO pUMmp3S45axWg4id1dNuaEwB4oXdyUlyvF4EgcdB386P8na+ldhG6XyWkt26KEpMA69c YaJevOudmZ8Q9+YbMp+V41+6fz69k8fNdjgK8= Received: by 10.210.30.1 with SMTP id d1mr2262506ebd.37.1246380572848; Tue, 30 Jun 2009 09:49:32 -0700 (PDT) Received: from ?127.0.0.1? (87-194-39-182.bethere.co.uk [87.194.39.182]) by mx.google.com with ESMTPS id 10sm722653eyd.38.2009.06.30.09.49.31 (version=SSLv3 cipher=RC4-MD5); Tue, 30 Jun 2009 09:49:32 -0700 (PDT) From: Tom Evans To: Alexander Best In-Reply-To: References: Content-Type: text/plain Date: Tue, 30 Jun 2009 17:49:30 +0100 Message-Id: <1246380570.2437.219.camel@strangepork.london.mintel.ad> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit 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 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 16:49:34 -0000 On Tue, 2009-06-30 at 18:12 +0200, Alexander Best wrote: > hi there, > > i need to output the header of a file to stdout. the header looks like this: > > struct Header > { > u_int8_t rom_entry[4]; > u_int8_t nintendo_logo[156]; > u_char game_title[12]; > u_char game_code[4]; > u_char maker_code[2]; > u_int8_t fixed_val; > u_int8_t unit_code; > u_int8_t device_type; > u_int8_t reserved_area1[7]; > u_int8_t software_version; > u_int8_t complement_check; > u_int8_t reserved_area2; > u_int8_t ram_entry[4]; > u_int8_t boot_mode; > u_int8_t slave_id; > u_int8_t unused_area[26]; > u_int8_t joybus_entry[4]; > }; > > if there a way to use printf or some other variant of *printf without using > sizeof()-loops for all the arrays? > > cheers. None of your arrays are dynamically sized, so surely write(fd, &hdr, sizeof(Header)); would do the trick? Cheers Tom