help me with C languaje please, re: files.
Victor Balada Diaz
victor at bsdes.net
Sun Jun 5 12:58:19 GMT 2005
On Sun, Jun 05, 2005 at 01:35:21AM -0400, Pablo Mora wrote:
> #include <stdio.h>
> #include <stdlib.h>
>
> 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.
More information about the freebsd-hackers
mailing list