0

I still can't understand why this printf is printing many 0 and the i++ is having no effect

    int i=0;
char datos[5]="";

while((fscanf(entry_file,"%5s",datos))==1)
{
    //Buffer para @
    char x;

    if((strcmp(datos,"DATOS"))==0)
    {
        fscanf(entry_file,"%lf%c%lf%c%lf%c%lf%c%lf%c%lf%c%lf",&cohetes[numCohetes].vuelos[0].aceleracionX[i],&x,&cohetes[numCohetes].vuelos[0].aceleracionY[i],&x,&cohetes[numCohetes].vuelos[0].aceleracionZ[i],
                &x,&cohetes[numCohetes].vuelos[0].altura[i],&x,&cohetes[numCohetes].vuelos[0].potencia[i],&x,&cohetes[numCohetes].vuelos[0].temperatura[i],&x,&cohetes[numCohetes].vuelos[0].tiempo[i]);
        printf("%d\n",i);
        i++;
        datos[0]='\0';
    }

}
Juan Diego
  • 1
  • 1
  • 1
  • `char datos[5]` --> `char datos[6]` – BLUEPIXY Oct 16 '14 at 12:49
  • If you want to discard a character , Use `%*c` instead of storing it in a variable. Your problem is that you forgot that strings are ending with a `\0` and you have to give space for it in the array as BLUEPIXY commented – Spikatrix Oct 16 '14 at 12:57

1 Answers1

3

Your variable datos is too small, so the ending null character is overwriting i.

Change the decalaration to:

char datos[6]="";
Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • 1
    @JuanDiego , "Thank You!" comments are frowned upon. Instead,accept/upvote the answer which solved the issue – Spikatrix Oct 16 '14 at 13:12