Problems with fscanf in C

Good night, I have a problem using fscanf to read some data from an input file, the problem is that by no means reads the file, this is the code snippet

FILE  *infile = NULL;
FILE  *outfile=NULL;

infile  = fopen("mtbank.in",  "r");
outfile = fopen("mtbank.out", "w");


char prueba[80];
fscanf(infile,"%s",&prueba);
printf("esto es una %s",prueba);

As a result you get:

esto es una °]¾

How can I fix this? Thank you!

 2
Author: MikeC, 2016-10-01

1 answers

The problem is that you are placing a & before test in the fscanf function.

So it should work properly.

fscanf(infile,"%s",prueba);

Remember that test is a vector and therefore it is also a pointer to the beginning of said vector (i.e. its memory address), this is why you should not place the &.

 3
Author: cventu, 2016-10-01 20:10:17