Alright, here we go:
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
#define DELAY 0.1
void options(void);
void write(void);
void read(void);
void pause(void) // creates 1 second pause
{
time_t second;
time(&second);
while(difftime(time(NULL),second) < DELAY)
;
}
int main()
{
FILE *password;
char enter_pass[11]; // used to make a password - open password
char temp_input[11];
int i; // used when string compare returns a value for password check
char menu;
int s; // encryption variable
password = fopen("Resources\\Datafiles\\password.dat","r");
if(password == NULL)
{
password = fopen("Resources\\Datafiles\\password.dat","w");
printf("Enter a password between 1 to 10 characters.\n");
scanf("%s",enter_pass);
for (s = 0;s < sizeof(enter_pass); ++s) // encryption
enter_pass[s] = enter_pass[s] + 13;
fprintf(password,"%s",enter_pass);
printf("Password Saved!\n\n");
fclose(password);
}
fread(enter_pass,11,1,password);
for (s = 0;s < sizeof(enter_pass); ++s) // decryption
enter_pass[s] = enter_pass[s] - 13;
printf("Enter Password: ");
scanf("%s",temp_input);
i = strcmp(enter_pass,temp_input);
if(i != 0)
{
printf("\nIncorrect Password\n");
pause();
exit(0);
}
else
{
printf("\nCorrect Password, Access Granted!\n");
}
fclose(password);
printf("\nWhat would you like to do?\n\n");
printf("A - Write\n");
printf("B - Read\n");
printf("C - Extras\n");
getchar(); // Absorbs the enter -> some1 @ wololo.net/talk/
menu = getchar();
fflush(stdin);
menu = toupper(menu);
switch(menu)
{
case('A'):
write();
break;
case('B'):
read();
break;
case('C'):
options();
break;
default:
printf("Invalid entry\n");
pause();
exit(0);
}
getch();
return(0);
}
void options(void)
{
FILE *read;
char menu;
char ch;
printf("\nA - Changelog\n");
printf("B - TODO List\n");
printf("C - Credits\n");
menu = getchar();
fflush(stdin);
menu = toupper(menu);
switch(menu)
{
case('A'):
read = fopen("Resources\\changelog.txt","r");
printf("Openning file... \n\n\n");
while(1)
{
ch = fgetc(read);
if(ch == EOF)
break;
printf("%c",ch);
}
printf("\n\n\nFile successfully read!\n");
fclose(read);
break;
case('B'):
read = fopen("Resources\\TODO.txt","r");
printf("Openning file... \n\n\n");
while(1)
{
ch = fgetc(read);
if(ch == EOF)
break;
printf("%c",ch);
}
printf("\n\n\nFile successfully read!\n");
fclose(read);
break;
case('C'):
read = fopen("Resources\\credits.txt","r");
printf("Openning file... \n\n\n");
while(1)
{
ch = fgetc(read);
if(ch == EOF)
break;
printf("%c",ch);
}
printf("\n\n\nFile successfully read!\n");
fclose(read);
break;
default:
printf("Incorrect entry\n");
pause();
exit(0);
}
}
void write(void)
{
FILE *write;
FILE *nfile;
char type;
printf("\nBegin typing - Press ~ then enter to save and quit\n\n\n");
write = fopen("Resources\\Documents\\write.dat","w");
while((type = getc(stdin)) != '~')
fputc(type,write);
printf("\n\nSaving & Quiting...\n");
fclose(write);
pause();
exit(0);
}
void read(void)
{
FILE *read;
char text;
char FileName[MAX_PATH];
// pick a program file
int ChooseProgram(PCHAR FileName)
{
FileName[0] = 0;
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.hInstance = NULL;
ofn.lpstrFilter = "Text Files\0*.txt\0\0";
ofn.lpstrFile = FileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Please Select A File To Open";
ofn.Flags = OFN_NONETWORKBUTTON |
OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY;
if (!GetOpenFileName(&ofn))
return(0);
return 1; }
int _cdecl main(int argc, char *argv[])
{
char FileName[MAX_PATH];
ChooseProgram(FileName);
return 0; }
/*printf("\nReading file... \n\n\n");
read = fopen("Resources\\Documents\\write.dat","r");
while((text = getc(read)) != EOF)
putchar(text);
printf("\n\n\nFile Successfully read!\n");
fclose(read);*/
}
The commented out code was what I had before, but it was only hardcoded to 1 file. I think I have good programming habits, so it shouldn't be too difficult to read.