The counter does not work in c

0

I present my problem, I have this struct:

typedef struct
{
    char nombre[20];
    unsigned int dni;
    tfecha nac;
}tperfil;

typedef struct
{
    int d, m, a;
}tfecha;

of which I have an array of the same and the idea of the counter is to brake when it encounters a 99 in the field DIA (a [u] .nac.d). Since I previously have code that adds 99 to the DIA field when there is no more data to be able to make a control cut.

int control(const tperfil a[])
{
    int u = 0;
    printf("%u %i\n", a[15].nac.d, u);
    while(a[u].nac.d < 99)
    {
        printf("%u %i\n", a[u].nac.d, u);
        u++;
    }
    return u;
}

I already know that in the a [15] there is a 99 in that field, the problem that appears is that as you can see in the first printf, it shows me the 99 as it should be, but the second printf that is the who shows me the tour shows me:

23 0
14 1
4 2
25 3
12 4
22 5
31 6
17 7
22 8
4 9
2 10
23 11
15 12
14 13
14 14
420070599 0
23 0
14 1
4 2
25 3
12 4
22 5
31 6
17 7
22 8
4 9
2 10
23 11
15 12
14 13
14 14

I do not understand why in position 15 he reads me that number and not the 99 that he showed me correctly before. The crashea program.

    
asked by Martin Curzel 06.01.2017 в 17:11
source

2 answers

0

You should first increase and then print, because when [u] .nac.d == 99 ends the shekel and does not give an opportunity to print.

while(a[u].nac.d != 99)
{
    u++;
    printf("%u %i\n", a[u].nac.d, u);
}
    
answered by 06.01.2017 в 18:14
-1

If there is a 99 in the a[15] as you say, you should not enter the while loop.

while(a[u].nac.d < 99)
    
answered by 06.01.2017 в 17:30