We help IT Professionals succeed at work.

# Function, Macro & Array Assignment Question.

on
Medium Priority
297 Views
This is an assignment question that I need assistance with.

'Write a simple address-book program that uses a function to read in the name, address and phone-numbers of BOOK_SIZE people (where BOOK_SIZE is a macro) and stores these values in an array of structures. Write another function that neatly displays this data in a table on the screen. Pass the array as an arguement to these functions.'
Comment
Watch Question

## View Solution Only

Commented:
Well, I don't know what is your question exactly so I'll write a source code that should do the trick :

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

#define BOOK_SIZE 5 /* Define the BOOK_SIZE macro */

struct T_BOOK  /* Define the Book structure type*/
{
};

void getbook(struct T_BOOK book[]);
void showbook(struct T_BOOK book[]);

void main(void)
{
struct T_BOOK book[BOOK_SIZE]; /* Define a book varible */
getbook(book);
showbook(book);
return(0);
}

void getbook(struct T_BOOK book[])
{
int i;

for (i = 0 ; i < BOOK_SIZE ; i++)
{
clrscr();
printf("Enter name #%d:\n",i+1);
gets(book[i].name;
printf("Enter number #%d:\n",i+1);
gets(book[i].number;
}
}

void showbook(struct T_BOOK book[])
{
int i;

clrscr();

for (i = 0 ; i < BOOK_SIZE ; i++)
{
printf("Name #%d: %s\n", i, book[i].name);
printf("Number #%d: %s\n", i, book[i].number);
if ( (i+1)*3 == 24 ) { getch(); clrscr(); }
}
}

Thats it. Thats the program. It reads BOOK_SIZE names to a BOOK_SIZE array of type T_BOOK structure, which contains name, number and address. Then it shows everything and pauses every 24 lines so you won't miss any.
Hope this helps.

Not the solution you were looking for? Getting a personalized solution is easy.

##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile