What is my Problem????? Please help me!!!! Read Value from File

Hi.
when i have a file with the follwing structur
4
12
23
34
45

which i need to get the values (if the above code), but what i really get printed on the screnn is

64
64
64
64
64

What is the problem?

#include
# include

int main(void)
{
FILE* Fich;
int valor, i=0;
int *p;
Fich = fopen("TESTE","r");
if (!Fich)
{
printf("
Error reading file.");
return NULL;
}
i = 0;
p = (int*)calloc(5,sizeof(int));
do
{
fscanf(Fich, "%d
", valor);
p[i] = valor;
printf("
%d",p[i]);
i++;
} while ( !feof(Fich) );
fclose(Fich);
return 0;
}

Comments

  • probably this line: valor must be passed by reference, not by value

    fscanf(Fich, "%d
    ", [red]&[/red]valor);
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion