Problems with fscanf in C

2

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

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 solve this? Thank you!

    
asked by MikeC 01.10.2016 в 09:40
source

1 answer

3

The problem is that you are placing an & before testing in the fscanf function.

This 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 (ie, its memory address), that is why you should not place the &.

    
answered by 01.10.2016 / 22:10
source