[Solved] After adding braces,file output not proper [closed]


You probably want this:

for (l=0; l<ny; l++)
{
  if (xflg)
    index = m * nxy + l*nx + k;
  else
    index = m * nxy + k*ny + l;

  vel[index] = velocity;

  fprintf(f,"%5d\n",index);  //<<< line added

  /* fprintf(stdout,"%.1f %.1f %.1f ", this_z, this_x, velocity); */
}

or maybe this:

for (l=0; l<ny; l++)
{
  if (xflg)
  {                                   //<<< brace added
    index = m * nxy + l*nx + k;
    fprintf(f,"%5d\n",index);         //<<< line added
  }                                   //<<< brace added
  else
    index = m * nxy + k*ny + l;

  vel[index] = velocity;
  /* fprintf(stdout,"%.1f %.1f %.1f ", this_z, this_x, velocity); */
}

I just added the fprintf line without any braces.

Your code is poorly indented, that’s one of the reasons why you are having difficulties.

This is your original code, exactly the same as mine above but without the fprintf(f,"%5d\n",index);:

 for (l=0; l<ny; l++)
            {
           if (xflg)
                  index = m * nxy + l*nx + k;
           else
              index = m * nxy + k*ny + l;
               vel[index] = velocity;
/*               fprintf(stdout,"%.1f %.1f %.1f ", this_z, this_x, velocity); */
            }

I hope you understand now what I meant by “poor indentation” and why correct indentation is important.

solved After adding braces,file output not proper [closed]