Question
C language, please help me fix the problem that i can;t print the data properly: #include #include struct Person{ char name[BUFSIZ]; char ssn[BUFSIZ]; int age;
C language, please help me fix the problem that i can;t print the data properly:
#include
#include
struct Person{
char name[BUFSIZ];
char ssn[BUFSIZ];
int age;
float height;
float weight;
};
void readData(struct Person x){
char buff[BUFSIZ];
printf("Name: ");
fgets(x.name,BUFSIZ,stdin);
printf("SSN: ");
fgets(x.ssn,BUFSIZ,stdin);
printf("Age: ");
x.age = atoi(fgets(buff,BUFSIZ,stdin));
printf("Height: ");
x.height = atof(fgets(buff,BUFSIZ,stdin));
printf("Weight: ");
x.weight = atof(fgets(buff,BUFSIZ,stdin));
}
void printData(struct Person x){
printf("Name = %s SSN = %s Age = %d Height(cm) = %g Weight(kg) = %g ", x.name, x.ssn, x.age, x.height, x.weight);
}
int main(){
struct Person a;
printf("Reading data ...... ");
readData(a);
printf(" ");
printf("Printing data .... ");
printData(a);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started