|
From: Gabriel A. <gab...@ud...> - 2004-11-22 22:55:47
|
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!
|