Code:
#include <stdio.h>
#include <ctype.h>
struct student
{
char* ID[10];
char* LastName[10];
char* FirstName[10];
char* DateOfBirth[10];
char* Address[10];
char* TelephoneNumber[10];
char* ProgramPursued[10];
};
struct student students[10]={
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a243","Spencer", "Sochelle", "22-05-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
{"a123","Hall", "Rayon", "16-06-87", "43_Olympic_Court", "898-0497", "Computer"},
};
char GetUserOption()
{
char option = 'I'; // 'I' for Invalid
while(option == 'I')
{
printf("\n");
printf("Choose one of the following options:\n\t\t\t[u]pdate [P]rint [S]earch [E]xit\n");
scanf("%c", &option);
switch(toupper(option))
{
case 'U':
case 'P':
case 'S':
case 'E':
break;
default:
option = 'I';
break;
}
}
return option;
}
void LetUserSearchForStudent()
{
int count;
char id,f;
printf("Enter the id you want to search for\n");
scanf("%c", & id);
f='b';
for(count=0; count<10; count++)
{
if(id== student students[count])
{
print("%c was found at location %d", id, count);
count=10;
f='a'
}
}
if (f=='b')
printf("%c was not found", id);
}
void PrintStudents(Student students[])
{
fprintf(fp, "%student", students[]);
}
void LoadStudents(Student students[])
{
FILE *fp=fopen("records.txt","r");
}
void UpdateStudents(Student students[])
{
FILE *fp=fopen("records.txt","a");
}
void SaveStudents(Student students[])
{
int i;
// Open the file for writing
FILE *fp = fopen("records.txt", "wb");
if(fp == NULL) return;
// Loop through each student
for(i = 0; i < 10; ++i)
{
// Write the student to the file....
fprintf(fp, "%s,%s,%s,%s,%s,%s,%s\r\n",
students[i].ID,
students[i].LastName,
students[i].FirstName,
students[i].DateOfBirth,
students[i].Address,
students[i].TelephoneNumber,
students[i].ProgramPursued
);
}
// Close the file
fclose(fp);
}
}
int main()
{
Student students[10];
int looping = 1;
// Load the students from the file
LoadStudents(students);
// Loop until exit
while(looping)
{
char option = GetUserOption();
switch(option)
{
case 'U':
UpdateStudents(Student students[]);
break;
case 'P':
PrintStudents(Student sudents[]);
break;
case 'S':
LetUserSearchForStudent()
break;
case 'E':
looping = 0; // exit the loop
break;
}
}
// Save the students to the file
SaveStudents(students);
return 0;
}