#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <iostream>
#include <time.h>
#include <windows.h>
#include <dos.h>
HANDLE wHnd;
HANDLE rHnd;
typedef struct contact {
int number;
char firstName[15];
char lastName[15];
char id[7];
char age[3];
char gender;
char field;
char phoneNumber[20];
char address[100];
struct contact *next;
int count;
} contact;
FILE *datafile;
contact *firstc, *currentc, *newc;
int cnum = 0;
void showOwnerInfo(){
puts("_______________________________________________");
puts("| |");
puts("| Simple Student Contact Information System |");
puts("| |");
puts("|_____________________________________________|\n");
}
void correct_contact_number(){
currentc = firstc;
int i=1;
while(1){
if(currentc){
currentc->number=i;
currentc = currentc->next;
//cnum++;
i++;
}else{
break;
}
}
}
void show(struct contact *currentc){
printf("--FIRST-NAME--:\t%s\n", currentc->firstName);
printf("---LASTNAME---:\t%s\n", currentc->lastName);
printf("------ID------:\t%.7s\n", currentc->id);
printf("------AGE-----:\t%s\n", currentc->age);
printf("----GENDER----:\t");
switch (currentc->gender) {
case '0':
puts("male");
break;
case '1':
puts("female");
break;
default:
puts("-");
break;
}
printf("-----FIELD----:\t");
switch (currentc->field) {
case '1':
puts("ComputerEngineering");
break;
case '2':
puts("ComputerScience");
break;
case '3':
puts("ElectricalEngineering");
break;
case '4':
puts("MechanicalEngineering");
break;
case '5':
puts("ChemicalEngineering");
break;
case '6':
puts("AeroSpaceEngineering");
break;
default:
puts("???");
break;
}
printf("-PHONE-NUMBER-:\t%.11s\n", currentc->phoneNumber);
printf("----ADDRESS---:\t%s\n", currentc->address);
puts("");
}
void find_cnum(){
currentc = firstc;
while(1){
if(currentc){
currentc = currentc->next;
cnum++;
}else{
break;
}
}
}
void display_all_contacts(void){
system("cls");
showOwnerInfo();
puts("-----------------------------------");
puts("-------DISPLAY ALL CONTACTS--------");
if(firstc==NULL){
puts("-----------------------------------");
puts("___________________________________");
puts("| |");
puts("| NO CONTACTS TO DISPLAY! |");
puts("|_________________________________|");
}else{
int num = 1;
currentc=firstc;
do{
printf("----------------[%d]----------------\n\n",num++);
show (currentc);
}
while((currentc=currentc->next) != NULL);
}
puts("press any key to continue:)");
getch();
}
void display_all_contacts_with_numbers(void){//display all of the contacts + number
if(firstc==NULL){
puts("___________________________________");
puts("| |");
puts("| NO CONTACTS TO DISPLAY! |");
puts("|_________________________________|");
}else{
int num=1;
currentc=firstc;
do{
printf("----------------[%d]----------------\n",num);
show (currentc);
num++;
}while((currentc=currentc->next) != NULL);
}
}
int go_to_contact_number_x (int x){//used in "changed" function (going to the next node X times!)(EXTRA!!!)
currentc = firstc;
for(int i = 0; i<x-1; i++){
if(currentc){
//previousa = currentc;
currentc = currentc->next;
}else{
return -1;//your contacts ar less than X!
}
}
return 1;
}
void add_contact(void) {//add a contact ***not useable in final version***
system("cls");
showOwnerInfo();
int boool =1,isDigit=0;//to check if the input is correct or not
newc = (struct contact *)malloc(sizeof(struct contact)); //allocate memory for our new structure(CONTACT!!!)
if (firstc == NULL) //if this contact is our 1st contact...
firstc = currentc = newc;
else {
currentc = firstc;// make the first record the current one
while (currentc->next != NULL)// pass the previous contacts
currentc = currentc->next;
currentc->next = newc; //pointer to next node
currentc = newc; //make current record the new one
}
//update the structure!!
cnum++;
puts("-----------------------------------");
puts("-------ADD A CONTACT TO LIST-------");
currentc->number = cnum; //I used "cnum" to give each contact a unique number
puts("-----------------------------------");
printf("Enter your contact's 1st name : \n");
getchar();
gets(currentc->firstName);
system("cls");
showOwnerInfo();
puts("-----------------------------------");
puts("-------ADD A CONTACT TO LIST-------");
puts("-----------------------------------");
printf("Enter %s's last name : \n",currentc->firstName);
gets(currentc->lastName);
system("cls");
showOwnerInfo();
puts("-----------------------------------");
puts("-------ADD A CONTACT TO LIST-------");
puts("-----------------------------------");
printf("Enter %s's student-ID : \n",currentc->firstName);
while(boool){
scanf("%s", currentc->id);
int j=0;
isDigit = 0;
while(currentc->id[j]!='\0'){
if(!isdigit(currentc->id[j])){
isDigit=1;
puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
puts("!! !!");
puts("!! WRONG INPUT...TRY AGAIN !!");
puts("!! !!");
puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
printf("Enter %s's student-ID :\n(only NUMBERs are supported!!!) \n",currentc->firstName);
break;
}
j++;
}
if(isDigit)
continue;
boool=0;
}
boool=1;
system("cls");
showOwnerInfo();
puts("-----------------------------------");
puts("-------ADD A CONTACT TO LIST-------");
puts("-----------------------------------");
printf("How old is %s? \n",currentc->firstName);
while(boool){
scanf("%s", currentc->age);
int j=0;
isDigit = 0;
while(currentc->age[j]!='\0'){
if(!isdigit(currentc->age[j])){
isDigit=1;
puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
puts("!! !!");
puts("!! WRONG INPUT...TRY AGAIN !!");
puts("!! !!");
puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
printf("Enter %s's age :\n(age is a NUMBER!!!) \n",currentc->firstName);
break;
}
j++;
}
if(isDigit)
continue;
boool=0;
}
boool=1;
system("cls");
showOwnerInfo();
puts("-----------------------------------");
puts("-------ADD A CONTACT TO LIST-------");
puts("-----------------------------------");
printf("Enter your contact's gender\n( 0 = male , 1 = female) : \n");
while(boool){
scanf( " %c",&(currentc->gender));
if(currentc->gender != '0' && currentc->gender != '1'){
puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
puts("!! !!");
puts("!! WRONG INPUT...TRY AGAIN !!");
puts("!! !!");
puts("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
puts("( 0 = male , 1 = female) : ");
continue;
}
boool=0;
}
boool=1;
system("cls");
showOwnerInfo();
puts("-----------------------------------");
puts("-------ADD A CONTACT TO LIST-------");
puts("-----------------------------------");
printf("Enter %s's field : \n",currentc->firstName);
printf("( 1 =\t Computer Engineering\n");
printf(" 2 =\t Computer Science\n");
printf(" 3 =\t Electrical Engineering\n");