Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript Site
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings




   Misc

   Amazon

   Links

    


Array of structures
 

 

 

Description

This shows how to use an array of structures

Code


#include <stdio.h>

/*the maximum amount of entries*/
#define MAXSITES 4


/*our structure*/
struct website{
char url[60];
char description[60];
int rating;
};

int main()
{
/*site is a variable of the structure website*/
struct website site[MAXSITES];
int count = 0;
int index;
/*get the url*/
printf("Enter the url of the website and press enter,\n");
/*get the description*/
while(count < MAXSITES && gets(site[count].url) != NULL && site[count].description != '\0')

{
printf("Now enter the description of the website.\n");
gets(site[count].description);
/*get the rating*/
printf("Now enter the rating out of 10.\n");
scanf("%d",&site[count++].rating);
while(getchar() != '\n')
continue;
if(count < MAXSITES)
printf("Enter the next url.\n");
}
/*display the entered info*/
for(index = 0;index < count ;index++)
{
printf("%s\n",site[index].url);
printf("%s\n",site[index].description );
printf("Is rated at %d out of 10\n",site[index].rating );
}
return 0;
}

Information

tested using Visual C++ 6

 

 

 

Download

structurearray.txt


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Find out part of a date(ASP)
alignment(HTML)
keypress example(Darkbasic)
Delete an empty directory(VB)
Stock ticker lookup(PHP)
CSV stock quotes(PHP)
removes a folder(VB)
Simple email sender(PHP)

    




Copyright © 2003 by programmershelp.co.uk