From owner-freebsd-questions@FreeBSD.ORG Fri Aug 1 04:14:30 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DBC817DA for ; Fri, 1 Aug 2014 04:14:30 +0000 (UTC) Received: from p3plsmtpa11-03.prod.phx3.secureserver.net (p3plsmtpa11-03.prod.phx3.secureserver.net [68.178.252.104]) by mx1.freebsd.org (Postfix) with ESMTP id 8B91F26CF for ; Fri, 1 Aug 2014 04:14:29 +0000 (UTC) Received: from ethic.thought.org ([209.180.213.209]) by p3plsmtpa11-03.prod.phx3.secureserver.net with id ZGEM1o0094XeM0101GENXZ; Thu, 31 Jul 2014 21:14:22 -0700 Date: Thu, 31 Jul 2014 21:14:39 -0700 From: Gary Kline To: Polytropon Message-ID: <20140801041439.GA13100@ethic.thought.org> References: <20140731233335.GA24151@ethic.thought.org> <20140801023749.8752a6b8.freebsd@edvax.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140801023749.8752a6b8.freebsd@edvax.de> (Subject: Re: how to grab text w/ fcanf User-Agent: Mutt/1.5.21 (2010-09-15) Cc: FreeBSD Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2014 04:14:30 -0000 ===== Organization: Thought Unlimited. Public service Unix since 1986. Of_Interest: With 28 years of service to the Unix community. On Fri, Aug 01, 2014 at 02:37:49AM +0200, Polytropon wrote: > On Thu, 31 Jul 2014 16:33:35 -0700, Gary Kline wrote: > > what is the easiest way, in C, *knowing the count=N*, to > > grab the *text files and stuff the paragraphs into a global > > buffer: char *parabuffer[1024]; ?? > > Addition: > > For every _desired_ file name you've obtained, do the > following: fopen() the file in "r" mode, fgets() the > line (or each line) into a read buffer, maybe postprocess > the buffer, and then append it to the parabuffer. Use > strlcat() to make sure you're not crossing the edge of > the string, so allocate sufficient space. Finally fclose() > the file when feof() tells you that the end has arrived. > THEN GOTO NEXT. :-) > > See "man strcat" on why not to use strcat() or strncat(), > section SECURITY CONSIDERATIONS. > here's the way I've done it so far: I've used readdir( DIR *d) and more to find the text[n].txt file names. then, in a 1998 c++ file I find these txt names by using essentially {psedocode): infp = fopen(filename[i], "r") while (fgets(buffer[i], sizeof buffer, infp)) fclose(infp); that's an immediate re-translation from c++ to C. thanks, polyt. I will put this last of several pieces of code together until I've got my several buffer[i] copied into the GTK label[i]. FWIW: the reason I want to have these several "labels" in a wudget//widows is to make the program less clumsy. it does work as-is; but it can get clumsy. -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix Twenty-eight years of service to the Unix community.