Solved

Function, Macro & Array Assignment Question.

Posted on 1997-04-04
1
256 Views
Last Modified: 2010-04-10
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.'
0
Comment
Question by:cyrax
1 Comment
 

Accepted Solution

by:
Phoenix020397 earned 50 total points
ID: 1162562
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*/
{
  char name[50], number[15], address[100];
};

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;
    printf("Enter address #%d:\n",i+1);
    gets(book[i].address;
  }
}

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);
    printf("Address #%d: %s\n", i, book[i].address);
    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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing the elements of a set declared inside a map in C++. 3 53
Using Diagnostic tools in VS2015: Unresoved allocations 19 106
Dialogbox API leak? 18 99
Unable to start eclipse ? 17 154
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question