HomeWork in C...... need in 10 hours

profileSamG
myenc.c

#include <stdio.h> #include <stdlib.h> typedef FILE* stream; typedef char* string; #define MAX_STUDENT 10 typedef struct { int id; char name[30]; }stStud; #define KEY 0xAB const string menu[]={"Add new student", "print Student information", "Quit"}; int displayMenu(void); void fnEncryptDecrypt(unsigned char * inBuf, int numBytes, unsigned char * outBuf); void AddNewStud(stStud * studList, int * count); void PrintStudentList(stStud * studList, int count); void loadStudInfoFromFile(stStud * studList, int * count); void WriteStudInfoToFile(stStud * studList, int count); int main(void) { stStud studList[MAX_STUDENT]; int count = 0; int sel; loadStudInfoFromFile(studList, &count); do { sel = displayMenu(); switch(sel) { case 1: AddNewStud(studList, &count); break; case 2: PrintStudentList(studList, count); break; case 3: // quit break; default: puts("Invalid Selection!!!"); } }while(sel!=3); WriteStudInfoToFile(studList, count); return 0; } int displayMenu(void) { int i; int sel; puts("\t\tStudent Menu"); for(i=0 ; i<sizeof(menu)/sizeof(menu[0]) ; ++i) { printf("%i. %s\n", i+1, menu[i]); } printf("Select: "); scanf("%i", &sel); return sel; } //add students to the array void AddNewStud(stStud * studList, int * count) { printf("Enter Student ID:"); scanf("%i", &studList[*count].id); printf("Enter Student name:"); scanf(" %39[^\n]", studList[*count].name); (*count)++; } void PrintStudentList(stStud * studList, int count) { int i; for(i=0;i<count;++i) { printf("Stud ID: %i, \t Student Name: %s\n", studList[i].id, studList[i].name); } } void loadStudInfoFromFile(stStud * studList, int * count) { int ret; stream in; unsigned char* buf; in = fopen("stud.bin", "rb"); if(in != NULL) { buf = (unsigned char *)malloc (sizeof(int)); ret = fread(buf,sizeof(int),1,in); if(ret == 1) { fnEncryptDecrypt(buf, sizeof(int), (unsigned char *) count); free(buf); buf = (unsigned char *) malloc ((*count) * sizeof(stStud)); fread(buf,(*count) * sizeof(stStud),1,in); fnEncryptDecrypt(buf , (*count) * sizeof(stStud), (unsigned char *) studList); } free(buf); fclose(in); } } void WriteStudInfoToFile(stStud * studList, int count) { stream out; unsigned char * buf; buf = malloc (sizeof(int)); fnEncryptDecrypt((unsigned char *) &count, sizeof(int), buf); out = fopen("stud.bin", "wb"); fwrite(buf,sizeof(int),1,out); free(buf); buf =(unsigned char*) malloc (count * sizeof(stStud)); fnEncryptDecrypt((unsigned char *) studList, count * sizeof(stStud), buf); fwrite(buf,count * sizeof(stStud),1,out); free(buf); fclose(out); } void fnEncryptDecrypt(unsigned char * inBuf, int numBytes, unsigned char * outBuf) { int i; for(i=0; i< numBytes;++i) { outBuf[i] = inBuf[i] ^ KEY; } }