|
From: Darren <dar...@nt...> - 2004-11-22 23:55:26
|
i can't see any problem with your logic though i would use
while ( !feof(nombre));
Rather than
while (c != EOF);
Perhaps you should debug and see what is being read from the file. also
consider how the file is layed out.
.
----- Original Message -----
From: "Gabriel Alejand Yañez 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 show
> the result on screen.This is the code.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main()
> {
> FILE *nombre;
> int c,a=0;
>
> nombre = fopen("Prueba.txt", "r");
>
> if (nombre == NULL)
> {
> printf("El archivo no existe \n");
> exit (EXIT_FAILURE);
> }
> else
> {
> do
> {
> c = getc(nombre);
> a=a +c;
>
> }
> while (c != 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
|