Solution for Exercise 24-3
ex2403 ex2403.h Header File
#include <stdio.h>
#include <stdlib.h>
/* prototypes */
void fillstructure(void);
void printstructure(void);
/* constants */
/* variables */
struct thing {
char name[32];
int age;
};
typedef struct thing human;
ex2403 main.c Module
#include "ex2403.h"
human person;
int main()
{
fillstructure();
printstructure();
return 0;
}
void fillstructure(void)
{
printf("Enter your name: ");
fgets(person.name,31,stdin);
printf("Enter your age: ");
scanf("%d",&person.age);
}
void printstructure(void)
{
printf("You are %s\n",person.name);
printf("And you are %d years old.\n",person.age);
}
Output
Enter your name: Danny
Enter your age: 39
You are Danny
And you are 39 years old.
Notes
The extra newline in the output (after Danny at Line 3) is read by the fgets() function.
Copyright © 1997-2025 by QPBC.
All rights reserved
