|
From: youngs <you...@ut...> - 2004-11-23 01:43:13
|
what you read is '2', '3', '3', not 2,3,3, so get wrong result.
you should use : c=3Dgetc(nombre)-'0' to get correct digital.
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Darren
Sent: 2004?11?23? 7:22
To: dev...@li...
Subject: Re: [Dev-C++] question about file
i can't see any problem with your logic though i would use
while ( !feof(nombre));
Rather than
while (c !=3D EOF);
Perhaps you should debug and see what is being read from the file. also
consider how the file is layed out.
=2E
----- Original Message -----
From: "Gabriel Alejand Ya=F1ez Lemus" <gab...@ud...>
To: <dev...@li...>
Sent: Monday, November 22, 2004 10:20 PM
Subject: [Dev-C++] question about file
> Hi!!
> I made a source code in C for read numbers from a file, plus them and s=
how
> the result on screen.This is the code.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
> FILE *nombre;
> int c,a=3D0;
>
> nombre =3D fopen("Prueba.txt", "r");
>
> if (nombre =3D=3D NULL)
> {
> printf("El archivo no existe \n");
> exit (EXIT_FAILURE);
> }
> else
> {
> do
> {
> c =3D getc(nombre);
> a=3Da +c;
>
> }
> while (c !=3D EOF);
> }
> printf("%d",a);
> fclose(nombre);
>
> return EXIT_SUCCESS;
> }
>
> I don't know why this code doesn't work. The file "prueba.txt" contains
> the numbers 2 3 and 3.The program must do "2+3+3" and show on screen "8=
"
> but i don't know what's wrong, the program shows "151".
>
> Help me please!
>
> Anybody have a good day!
>
>
>
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.797 / Virus Database: 541 - Release Date: 15/11/04
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|