Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

8.

4


8.3

/*
ipstruc1.c
*/
#include <stdio.h>
/* gets() in this file */
/* 1 */
#include <stdlib.h>
/* atoi(),atof() in this file */
/*
2 */
#include <conio.h>
/* 4 */
void main(void)
/*
5 */
{
/* 6 */
struct person
/* 7 */
{
/* 8 */
char name[20];
/* 9 */
float salary;
/* 10 */
int age;
/* 11 */
};
/* 12 */
struct person one;
/* 13 */
char numstr[81];
/* 14 */
clrscr();
/* 15 */
printf("\n *** Person Data ***\n\n Enter name : ");
/* 16 */
gets(one.name);
/* 17 */
printf("Enter salary : ");
/* 18 */
gets(numstr);
/* 19 */
one.salary=atof(numstr);
/* 20 */
printf("Enter age : ");
/* 21 */
gets(numstr);
/* 22 */
one.age=atoi(numstr);
/* 23 */

printf("\n\nName = %s\n",one.name);
printf("Salary = %f\n",one.salary);
printf("Age = %d\n",one.age);
printf("\n\nPress any key back to program...");
getch();
}

/* 24 */
/* 25 */
/* 26 */
/* 27 */
/* 28 */
/* 29 */

8.3
7 person
13 one
17 name one
19 20 numstr
salary one
22 23 numstr
age one
24 26 name, salary age one

8.4

/*
ipstru2.c
*/
#include <stdio.h>
/* gets() in this file */
#include <stdlib.h> /* atoi(),atof() in this file */
2 */
#include <conio.h>
void main(void)
{
struct person
{
char name[20];
float salary;
int age;
};
struct person one ,two;
char numstr[81];
clrscr();
printf("\n *** Person Data ***\n\n Enter name : ");
15 */
gets(one.name);
printf("Enter salary : ");
gets(numstr);
one.salary=atof(numstr);
printf("Enter age : ");
gets(numstr);
one.age=atoi(numstr);
two = one;
/*copy struct one to struct two*/
printf("\n\nName1 = %s\n",one.name);
printf("Salary1 = %f\n",one.salary);
printf("Age1 = %d\n",one.age);

/* 1 */
/*
/* 3 */
/* 4 */
/* 5 */
/* 6 */
/* 7 */
/* 8 */
/* 9 */
/* 10 */
/* 11 */
/* 12 */
/* 13 */
/* 14 */
/*
/* 16 */
/* 17 */
/* 18 */
/* 19 */
/* 20 */
/* 21 */
/* 22 */
/* 23 */
/* 24 */
/* 25 */
/* 26 */

printf("\n\nName2 = %s\n",two.name);
printf("Salary2 = %f\n",two.salary);
printf("Age2 = %d\n",two.age);
printf("\n\nPress any key back to program...");
getch();
}

/* 27 */
/* 28 */
/* 29 */
/* 30 */
/* 31 */
/* 32 */

8.4
23 two = one; ipstru2.c
one two

You might also like