#include %26lt;stdio.h%26gt;
struct tele { // Struct with 2 fields for phone numbers.
char home [20]; // Holds phone numbers in an array of characters.
char mobile [20];
};
typedef struct student { //Typedef struct to hold- names [characters]
char firstname [20]; // - id and average [intergers]
char lastname [20];
int id;
float avg;
struct tele phone; //Nested struct. The struct 'tele' is called 'phone'
// and its holds both home and mobile numbers.
} data; // New type
void main ()
{
int j; //Declared interger 'j'.
data rec [10]; //Typedef struct data- decleared array 'rec' that can hold 10 'student'.
data stdinfo;
struct tele call; //'call' declared as a struct.
for(j=0;j%26lt;2;j++){ //For loop used to get infomation for array -loops twice-.
printf("Enter First Name\n"); //Scans for First Name and it is put
scanf("%s", stdinfo.firstname); //into 'fname' in struct 'person'.
printf("\nEnter Last Name\n"); //Scans for Last Name and it is put
scanf("%s", stdinfo.lastname); //into 'lname' in struct 'person'.
printf("\nEnter Home Phone Number\n"); //Scans for Home Phone Number and it is put
scanf("%s", call.home); //into 'home' in struct 'call'.
printf("\nEnter Mobile Phone Number\n"); //Scans for Mobile Phone Number and it is put
scanf("%s", call.mobile); //into 'mobile' in struct 'call'.
printf("\nEnter ID Number\n"); //Scans for ID Number and it is put
scanf("%d", %26amp;stdinfo.id); //into 'id' in struct 'person'.
printf("\nEnter Average\n"); //Scans for average and it is put
scanf("%f", %26amp;stdinfo.avg); //into 'avg' in struct 'person'.
stdinfo.phone=call; //All information in struct 'comm' is put into 'ph' field in 'person'
printf("\n\nName- %s %s\n",stdinfo.fname,stdinfo.lname); //Pr... collected information
printf("ID # %d\n",stdinfo.id); //from structs.
printf("Average %.2f\n",stdinfo.avg);
printf("Home Phone # %s\n",stdinfo.phone.home);
printf("Mobile Phone # %s\n\n\n",stdinfo.phone.mobile);
rec [j] = stdinfo;//all information is put into the array of records
} //For loop ends
j=0;
for (j=0;j%26lt;2;j++){ //For loop used for printing information.
printf("\n\n**************************...
//Printing directly from the array of records
printf("Information at array location %d is:\n\n",j);
printf("Name- %s %s\n",rec[j].fname,rec[j].lname);
printf("ID # %d\n",rec[j].id);
printf("Average %.2f\n",rec[j].avg);
printf("Home Phone # %s\n",rec[j].phone.home);
printf("Mobile Phone # %s\n\n",rec[j].phone.mobile);
} //For loop ends
} //END
C program to record stored information from an array, and print out stored information.?
hey ur code looks fine. .wats ur ques?
jj
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment