Article View: comp.std.c
Article #4383Help with huge arrays
From: Mike Chilcott
Date: Mon, 20 Nov 1995 02:21
Date: Mon, 20 Nov 1995 02:21
123 lines
3852 bytes
3852 bytes
I am using Borland TC 3.0 for DOS and don't know what to do???
Comes up saying I need to use huge ???
/*
* This program will open a file that the user specifies, read
* all the data into an array, and ask the user what they want
* to do a search on. The program will then display the desired
* data, and ask the user for another search, or Quit.
* It will then close the file and end.
*/
#include <string.h>
#include <stdio.h>
#define MAXLINE 80 /* number of characters in a line */
#define MAX 15000 /* number of records */
struct a_record_struct {
char stanum[6];
char calltr[5];
char name[19];
char state[2];
char country[2];
char rwlat[5];
char rwlon[6];
char elev[4];
};
main ()
{
char ca[5]; /* call letters */
char na[19]; /* plain language name */
char sn[6]; /* station number */
char req; /* request */
int i; /* loop counter for array */
FILE *src_file; /* file pointer */
struct a_record_struct a_record[MAX];
/*
* Open input file for reading
*/
if((src_file=fopen("mscstaot.doc", "r")) == NULL)
printf("File cannot be opened!\n");
else {
for(i = 0; i <= MAX; i++)
fread(&a_record, sizeof (struct a_record_struct), 1, src_file);
/*
* Ask user what to search for .... store it in &req
*/
printf("This program will search the file for a (S)tation number,\n");
printf("\t(C)all Letter, (N)ame or (Q)uit.\n");
printf("\tEnter either S, C, N or Q to continue.\n");
scanf("%c",&req);
/*
* If user wants STATION NUMBER do this
*/
if(&req == "s"){
printf("Enter Station Number: ");
gets(sn);
for(i=0; i<=MAX; i++){
if((strcmp(sn, a_record[i].stanum)==0)){
printf("%s\n",a_record[i].stanum);
printf("%s\n",a_record[i].calltr);
printf("%s\n",a_record[i].name);
printf("%s\n",a_record[i].state);
printf("%s\n",a_record[i].country);
printf("%s\n",a_record[i].rwlat);
printf("%s\n",a_record[i].rwlon);
printf("%s\n",a_record[i].elev);
}
}
}
/*
* If user wants CALL LETTER do this
*/
if(&req == "c"){
printf("Enter Call Letters: ");
gets(ca);
for(i=0; i<=MAX; i++){
if((strcmp(ca, a_record[i].calltr)==0)){
printf("%s\n",a_record[i].stanum);
printf("%s\n",a_record[i].calltr);
printf("%s\n",a_record[i].name);
printf("%s\n",a_record[i].state);
printf("%s\n",a_record[i].country);
printf("%s\n",a_record[i].rwlat);
printf("%s\n",a_record[i].rwlon);
printf("%s\n",a_record[i].elev);
}
}
}
/*
* If user wants NAME do this
*/
if(&req == "n"){
printf("Enter Plain Language Name: ");
gets(na);
for(i=0; i<=MAX; i++){
if((strcmp(na, a_record[i].name)==0)){
printf("%s\n",a_record[i].stanum);
printf("%s\n",a_record[i].calltr);
printf("%s\n",a_record[i].name);
printf("%s\n",a_record[i].state);
printf("%s\n",a_record[i].country);
printf("%s\n",a_record[i].rwlat);
printf("%s\n",a_record[i].rwlon);
printf("%s\n",a_record[i].elev);
}
}
}
}
fclose(src_file);
return(0);
}
--
===========================================================
Mike Chilcott mikechil@cris.com
Home Computer Services http://www.cris.com/~mikechil/
=====================================================================
Technical Details
Message-ID:
<48oonl$b7k@spectator.cris.com>Path:
arc1-ca.pugleaf.net!news1.cris.com!newsShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news1.cris.com!news From: mikechil@cris.com (Mike Chilcott) Newsgroups: comp.std.c Subject: Help with huge arrays Date: 20 Nov 1995 02:21:41 GMT Organization: Home Computer Services Message-ID: <48oonl$b7k@spectator.cris.com> NNTP-Posting-Host: crc5-fddi.cris.com Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII X-Newsreader: WinVN 0.99.6