home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light
/
Light_Vol.1_August_1992_Datasphere_Publications_Disk_1_of_2_Side_A.d64
/
arrays.c
< prev
next >
Wrap
Text File
|
2023-02-26
|
3KB
|
121 lines
/*
Arrays, Pointers & Structures - Chapter 3
Below is an array of structures to hold upto 6 (0-5) names & phone numbers.
Firstly a structure with the tag "book" is defined, followed by a
declaration of an array of structure book called names.
*/
#include "stdio.h"
#include "ctype.h"
#define clear_screen printf("\223")
struct book {SHIFT-+} char surname[15];
char forename[20];
long phone; {SHIFT--};
struct book names[6] = {SHIFT-+} "Smith", "Pete",633261,
"Askwith", "Bob",471263,
"Wilkinson", "Kerry",798624,
"Fry", "Andy",623879,
"Parker", "Chris",299311 {SHIFT--};
main()
{SHIFT-+}
int i,number,range=4;
static int totals[10];
char *words[2];
char temp,choice;
words[0] = "Computer";
words[1] = "Disk Drive";
words[2] = "Happy-Stick";
clear_screen;
printf("String Arrays");
printf("\n\nThe following words are held in the");
printf("\narray *words[3] :\n\n");
for(i=0; i<3; i++)
{SHIFT-+}
printf("\nwords[%d] = %s",i,words[i]);
{SHIFT--}
printf("\n\nPress a key...");
getchar();
clear_screen;
printf("Number Arrays\n\n");
for(i=0; i<10; i++)
{SHIFT-+}
totals[i] = i*i;
printf("\ntotals[%u] = %d",i,totals[i]);
{SHIFT--}
/* --- the %u outputs an unsigned integer. On
other examples displaying integers you
might have noticed a space in front of
each number, this is left for the
minus sign when necessary. ---*/
printf("\n\nPress a key...");
getchar();
do
{SHIFT-+}
clear_screen;
printf("Structures");
printf("\n\nEnter number (0-%u): ",range);
do
{SHIFT-+} /* only accepts */
scanf("%d",&number); /* numbers within */
{SHIFT--} /* range */
while(number <0 {CBM--}{CBM--} number >range);
printf("\n\nSurname : %s",names[number].surname); /* displays array */
printf("\nForename : %s",names[number].forename); /* element to */
printf("\nPhone : %lu",names[number].phone); /* screen */
printf("\n\nEnter any surname : "); /* accepts 6th */
scanf("%s",names[5].surname); /* element */
printf("\nEnter any forename : ");
scanf("%s",names[5].forename);
printf("\nEnter any phone no ");
printf("\n(99 to end) : ");
scanf("%d",&names[5].phone);
range = 5; /* range is now */
{SHIFT--} /* 0 to 5 */
while (names[5].phone != 99);
printf("\n\nPress... S for binary Search,");
printf("\n B for Bubble sort or,");
printf("\n any for Menu");
temp = getchar();
choice = toupper(temp);
switch(choice) {SHIFT-+}
case 'S' : printf("\n\nSearching...Loading binary search...");
exec("search"); break;
case 'B' : printf("\n\nMore bubbles for your money...");
exec("bubble"); break;
default : printf("\n\nJust waiting for that menu to load....");
exec("c-menu"); break;
{SHIFT--}
{SHIFT--}