Code:
void initialize ( int ids [] , char * names [], char * address[], char* phone[], char*course[],
char *campus[],char *courseID[]);
void initialize( int ids [] , char * names [] , char * address[],char *phone[], char *course[],
char *campus[],char*courseID[])
{
int i ;
for ( i=0 ; i<MAX ; i++)
{
ids [i] =0;
names[i] = malloc (50);
address[i] = malloc(100);
phone[i] = malloc (25);
course[i] = malloc (30);
campus[i] = malloc (20);
courseID[i] =malloc (5);
}
}
(\code)-----------------------------------------------------------------------
Since the info such as campus and course are constant, I thought this strategy of initializing them would help later in the assignment. My trouble is when I attempt to list the student information. It only works for one student? When I add another student-- I only get the name and address to display. Any help is greatly appreciated.
Thanks Libby.
code-----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include< string.h>
#define MAX 100
#include "menu.h"
#include "initialize.h"
//---------------FUNCTION PROTOTYPES------------------------------------------------------
void adding ( int ids [] , char *names [], char * address[],
char* phone[], char*course[], char *campus[]);
void deleting ( int ids [], char *names []);
void list_all ( int ids [], char *names [], char *address[],
char*course[],char *campus[]);
//----------------------------------------------------------------------------------------------
void main ()
{
int selection;
int ids [MAX];
char * names [MAX];
char * address[MAX];
char * phone[MAX];
char * campus[MAX];
char * course[MAX];
char *courseID[MAX];
//STEP I : Initialization of the database by calling function
initialize ( ids , names, address, phone,course,
campus, courseID );
// STEP II
do
{
selection=main_menu ();
switch (selection)
{
case 1 : adding ( ids , names, address, phone, course, campus);
break;
case 2: deleting ( ids , names);
break;
case 3: list_all( ids ,names,address,course, campus);
break;
}
}while ( selection !=0 );
} /* end of main*/
/* adding function body*/
void adding ( int ids [], char *names[], char *address[], char* phone[], char*course[],char*campus[])
{
int i=0, title, location;
char yesno;
char *c1[] = {"Intro. Programming"};
char *c2[] = {"C Programming "};
char *c3[]= {"Java "};
char *c4[]= {"Visual Basic "};
char *c5[]= {"Web Publishing "};
char *loc1[]= {"West"};
char *loc2[]= {"Osceola"};
char *loc3[]={ "Winter Park"};
char *loc4[]= {"East"};
while ( ids [i] != 0 && i<100) {i++;}
if ( i==100) printf (" Sorry FULL \n\n");
else
{
printf ("Enter Id here :");
scanf ("%d", &ids[i]);
printf (" Enter Name :");
fflush (stdin);
gets(names[i]);
printf (" Enter Address :");
fflush (stdin);
gets(address[i]);
printf (" Enter Phone Number :");
fflush (stdin);
gets(phone[i]);
// }
system("cls");
//}
printf(" Do you wish to register for a course ?\n");
printf(" Enter y or Y --> Yes or n or N --> N \n\n");
fflush(stdin);
scanf( "%c" , &yesno);
if( yesno == 'y' || yesno =='Y')
system("cls");
printf (" \n\n \t\t\tEnter Course\n :");//
printf(" 1 --> Intro. Programming 2 --> C Programming\n");
printf(" 3 --> Java 4 --> Visual Basic\n");
printf(" 5 --> Web Publishing \n");
printf(" Enter your Selection: ");
scanf("%d", &title);
system("cls");
switch(title)
{
case 1:
strcpy(*course, *c1);
case 2:
strcpy( *course, *c2);
break;
case 3:
strcpy(*course, *c3);
break;
case 4:
strcpy( *course, *c4);
break;
case 5:( *course, *c5);
break;
default: printf(" /t/tPlease Enter a valid course selection\n");
break;
}
printf( " \n\n");
printf( " Enter a campus Location:\n");
printf(" Press:\n");
printf(" 1 --> West 2 --> Osceola");
printf(" 3 --> Winter Park 4 --> East\n");
printf(" Enter your Selection");
scanf("%d", &location);
switch(location)
{
case 1:
strcpy( *campus, *loc1);break;
case 2:
strcpy( *campus, *loc2);break;
case 3:
strcpy( *campus, *loc3);break;
case 4:
strcpy( *campus, *loc4);break;
default: printf(" /t/tPlease Enter a valid campus location:");
break;
}
}
}
//end of adding
void list_all (int ids [],char *names[],char *address[],char*course[],char*campus[] )
{
int i;
printf(5s\n", "CID", "NAME","ADDRESS", "COURSE",
"CAMPUS" );
printf("_______________________________________________\n"
for ( i=0 ; i<100 ; i++)
if (ids[i]!=0)
printf ("%d%15s%15s%15s%15s\n\n", ids[i],names[i],address[i],course[i],campus[i]);
}
void deleting ( int ids [], char *names [])
{
printf (" NOT READY YET....\n\n");
}