StructProgramming

C program to stored record information in an array and print out the s

Page 1 of 1

2 Replies - 773 Views - Last Post: 22 October 2007 - 07:37 AM Rate Topic: -----

#1 peaceworlds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-October 07

StructProgramming

Post icon  Posted 22 October 2007 - 06:04 AM

C program to record stored information from an array, and print out stored information.? // please help me understand this a little more.
#include <stdio.h>

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<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", &stdinfo.id); //into 'id' in struct 'person'.

printf("\nEnter Average\n"); //Scans for average and it is put 
scanf("%f", &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,stdin... //Printing 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.m...

rec [j] = stdinfo;//all information is put into the array of records

} //For loop ends


j=0;
for (j=0;j<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]...
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.mobi...

} //For loop ends

} //END


This post has been edited by Amadeus: 22 October 2007 - 06:11 AM


Is This A Good Question/Topic? 0
  • +

Replies To: StructProgramming

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: StructProgramming

Posted 22 October 2007 - 06:12 AM

Forgive me for asking, but what is the problem? Do you have specific questions about the program, or would you just like an overview of what it does?
Was This Post Helpful? 0
  • +
  • -

#3 peaceworlds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-October 07

Re: StructProgramming

Posted 22 October 2007 - 07:37 AM

Hi sorry, i am so new to this forum and having a bit of a hard time gettign around it...however what i really wanted was for a sort of another solution to this question using the same sort of format like for example the typedef and struct.
I hope i am explaining my self clearer.




View PostAmadeus, on 22 Oct, 2007 - 06:12 AM, said:

Forgive me for asking, but what is the problem? Do you have specific questions about the program, or would you just like an overview of what it does?

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1