I was trying to print a string and an integer using array of structs and code seems to be fine, but in the output instead of 1 line of values, after each string a new line is automatically added. Can someone please help?
#include <stdio.h>
typedef
struct player_main{
char name[20];
int total;
}
player;
void print(player pprint);
void scan(player *pscan);
int main(){
player user[2];
for(int i = 0; i < 2; i++){// scanned
printf("Player %d", i+1);
scan(&(user[i]));
}
for(int i = 0; i < 2; i++){// printed
print(user[i]);
}
return 0;
}
void print(player pprint){
printf("%s Weight:%d kg\n", pprint.name, pprint.total);
}
void scan(player *pscan){
printf("\nName: \n");
fgets(pscan->name, 20, stdin);
printf("\nEnter weight:");
scanf("%d%*c", &(pscan->total));
}
Example of desired output:
Player A, 50 kg Player B, 60 kg
Actual output:
Player A,
50 kg
Player B,
60 kg