From owner-freebsd-hackers@FreeBSD.ORG Sun Jun 5 12:58:19 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C055116A41C for ; Sun, 5 Jun 2005 12:58:19 +0000 (GMT) (envelope-from victor@bsdes.net) Received: from alf.dyndns.ws (244.Red-217-126-240.pooles.rima-tde.net [217.126.240.244]) by mx1.FreeBSD.org (Postfix) with ESMTP id E351743D48 for ; Sun, 5 Jun 2005 12:58:18 +0000 (GMT) (envelope-from victor@bsdes.net) Received: from alf.dyndns.ws (pato.euesrg02.net [192.168.0.3]) by alf.dyndns.ws (8.13.1/8.13.1) with ESMTP id j55CwH6q022193 for ; Sun, 5 Jun 2005 14:58:17 +0200 (CEST) (envelope-from victor@bsdes.net) Date: Sun, 5 Jun 2005 14:57:46 +0200 From: Victor Balada Diaz To: freebsd-hackers@freebsd.org Message-ID: <20050605125746.GB691@pato.euesrg02.net> Mail-Followup-To: Victor Balada Diaz , freebsd-hackers@freebsd.org References: <20050604181730.GB49520@pato.euesrg02.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i Subject: Re: help me with C languaje please, re: files. 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: Sun, 05 Jun 2005 12:58:19 -0000 On Sun, Jun 05, 2005 at 01:35:21AM -0400, Pablo Mora wrote: > #include > #include > > int main(void) { > > FILE *p_to_f; > char buf[1024]; > int i, j = 0; > > p_to_f = fopen("test","r"); > > if(p_to_f == NULL) { > perror("fopen"); > exit(EXIT_FAILURE); > } > > for(i = 0; i < 4 && !feof(p_to_f); i++) { > fgets(buf,1024,p_to_f); > printf("%s", buf); > } > > fclose(p_to_f); > > return 0; > > } > > I expect that be well what I did. Thanks Victor. > > PD Corrigeme Si hay algo malo. :D You don't use j, in the for should be || instead of && and you don't check for errors in fgets. Btw, i think that this is not the best place for ask this questions, you should ask in a c programming list. -- La prueba mas fehaciente de que existe vida inteligente en otros planetas, es que no han intentado contactar con nosotros.