Help me with fscaf

Hello, i dont found the error of the function fscaf, look my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include<stdbool.h>



typedef struct{
    float real_part;
    float imag_part;
    char sinal;
    char Equal;
    char delimitador;
}complex_retang;

typedef struct {
    float modulo;
    float angulo;
    char sinal;
    char Equal;
    char delimitador;
}complex_polar;

union complexo {
    complex_retang a;
    complex_polar b;
};

int main()
{
   float  i;
   FILE *arquivo = fopen("dados1.txt", "r");
   int caractere;
   int quant_linhas = 0;

    while((caractere = fgetc(arquivo)) != EOF){
        if(caractere == '\n'){
                quant_linhas++;
            }
    }
    rewind(arquivo);//Volta ao incio do arquivo
    union complexo x[quant_linhas];

    for(i = 0; i < quant_linhas; i++){
        fscanf(arquivo, "%f", &x[i].a.real_part);
    }

    printf("%d", quant_linhas);

    fclose(arquivo);

    return 0;
}
Last edited on
What makes you think there's an error?
inl ine 45
1
2
3
float i ;
....
... &x[i] ... // *** error: array subscript is not an integer 

http://coliru.stacked-crooked.com/a/9e65324ebabfc585
Last edited on
Topic archived. No new replies allowed.