ahh i see sir... XD
because it would be obvious that it's written by someone who knows more C than your teacher, most likely
lol....
but my code is not something like [read, manipulate, overwrite...] T.T thats why im doomed... i can even barely make the add_student work T.T
btw, here's my noobish code
Code:
#include <stdio.h>
#include <string.h>
typedef struct student_info{
long long int stud_num;
char name[50];
char bday[30];
char course[50];
} student;
void login(char username[], char password[]);
char admin(void);
void add_student(student accounts[20], FILE *file);
//*******************************************************************
int main(void)
{
char option;
char temp[100];
char username[30];
char password[30];
student accounts[20];
FILE *file = fopen("Data/Accounts.txt", "a+");
clrscr();
login(username, password);
if(strcmp(username, "ADMIN") == 0 && strcmp(password, "admin") == 0)
{
option = admin();
switch(option)
{
case '1' : {
clrscr();
printf("\n\nThis is the [Add a Student Account] Function.\n\n");
printf("--------------------------------------------------------");
add_student(accounts, file);
break;
}
default : printf("\n\nInvalid option.\n\n");
}
}
else
{
gotoxy(19, 24); printf("Invalid username or password.");
}
fclose(file);
getche();
return 0;
}
//*******************************************************************
void login(char username[], char password[])
{
clrscr();
gotoxy(19,5); printf("********* ******** *** *** *********");
gotoxy(19,6); printf("** *** ** *** *** *** ** ***");
gotoxy(19,7); printf("** ** ** *** *** *** ** **");
gotoxy(19,8); printf("*** ** *** **** **** *** ");
gotoxy(19,9); printf("******** ******* ** *** ** ******** ");
gotoxy(19,10); printf(" ******** ** *** ** *** ** ********");
gotoxy(19,11); printf(" *** ** ** ** * ** ***");
gotoxy(19,12); printf("** ** ** ** ** ** ** **");
gotoxy(19,13); printf("*** ** ** ** ** ** *** **");
gotoxy(19,14); printf("********* *** *** **** **** *********");
gotoxy(45,45); printf("Student Record Management System");
gotoxy(19,18); printf("Enter username:");
gotoxy(35,18); gets(username);
gotoxy(19,20); printf("Enter password:");
gotoxy(35,20); gets(password);
}
//*******************************************************************
char admin(void)
{
char option;
clrscr();
printf("\n\n-----Welcome Administrator!!!-----\n");
printf("\n[1] --- Add a Student");
printf("\n[2] --- Modify a Student Account.");
printf("\n[3] --- Delete a Student Account.");
printf("\n[4] --- Display all Student Acount Entries.");
printf("\n[5] --- Logout");
printf("\n[6] --- Terminate Program.\n");
printf("\n\nPlease choose the task you want to perform.\n\n");
scanf("%c", &option);
return option;
}
//*******************************************************************
void add_student(student accounts[20], FILE *file)
{
int i;
int free;
for(i = 0; i < 20; i++)
{
if(accounts[i].stud_num == NULL)
free = i;
}
printf("\n\nEnter student information:\n\n");
printf("\n\nStudent Number [which will be the account's username]:\n\n\n\t\t");
scanf("%lld", &accounts[free].stud_num);
fprintf(file, "%lld", accounts[free].stud_num);
fputs("\t\t", file);
printf("\n\nName:\t\t");
gets(accounts[free].name); // i dont know why 2 gets(); work while 1 gets(); doesnt...
gets(accounts[free].name);
fprintf(file, "%s", accounts[free].name);
fputs("\t\t", file);
printf("\nBirthdate:\t");
gets(accounts[free].bday);
fprintf(file, "%s", accounts[free].bday);
fputs("\t\t", file);
printf("\nCourse:\t\t");
gets(accounts[free].course);
fprintf(file, "%s", accounts[free].course);
fputs("\n", file);
printf("\n\nAccount creation successful.\n");
}
//*******************************************************************