Print one number after the last word

Viewed 40
while(!feof(fp)) {
  printf("\n %s %s %s", post.name, post.lastnamn, post.clubb);
  for(i = 1; i <= x; i++;)
  {
    printf(" %d", j.number[i]);
  }
  fread(&post, sizeof(postTyp), 1, fp);
}

I have created two typedef struct and I am referring to them with post and j.

I have created a program that asks for a users name, last-name and clubb and stores it in a text file. I have also created a program that creates x amount of numbers in the array number[i] and save it in a text file. x counts how many times you have run a program to create an name, last-name and clubb. So if you run the program 3 times 3 numbers will be created like example down below

So when i print it i get this

Hanna Svensson FCB 1 2 3
Fabian Svensson FCB 1 2 3
Patrik Svensson FCB 1 2 3

What i want is to print it like this

Hanna Svensson FCB 1
Fabian Svensson FCB 2 
Patrik Svensson FCB 3

Any tips for how I may accomplish this?

1 Answers

The solution is to only use the outer loop and not the inner one

i=1;
while(!feof(fp))
{
    printf("\n %s %s %s", post.name, post.lastnamn, post.clubb);
    printf(" %d", j.number[i]);
    i++;
    /* ...*/
}

Note aside: your while loop construct is very quetionable.

Related