From owner-freebsd-questions@FreeBSD.ORG Fri Aug 1 00:37:52 2014 Return-Path: Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 56F75489 for ; Fri, 1 Aug 2014 00:37:52 +0000 (UTC) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1AB4820A6 for ; Fri, 1 Aug 2014 00:37:51 +0000 (UTC) Received: from r56.edvax.de (port-92-195-69-249.dynamic.qsc.de [92.195.69.249]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id 4218827640; Fri, 1 Aug 2014 02:37:50 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id s710boRO004093; Fri, 1 Aug 2014 02:37:50 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Fri, 1 Aug 2014 02:37:49 +0200 From: Polytropon To: Gary Kline Subject: Re: how to grab text w/ fcanf Message-Id: <20140801023749.8752a6b8.freebsd@edvax.de> In-Reply-To: <20140731233335.GA24151@ethic.thought.org> References: <20140731233335.GA24151@ethic.thought.org> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 00:37:52 -0000 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. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...