Я пытаюсь работать над простым приложением самостоятельно на C. Это позволяет любому создать свою учетную запись и сохранить ее личную информацию, и это безопасно. До сих пор пользователь может создать свою учетную запись, когда когда пользователь возвращается при регистрации он не может. Я написал и использовал файловый ввод-вывод для сохранения учетных данных пользователя.
#include <stdio.h>
#include <string.h>
#include "cs50.h"
int main (int argc, string argv[])
{
// The pointer to the File
FILE* accountsDatabase = fopen("accountsDatabase.txt", "r+");
char Fdecision;
char Gateway = 'Y';
char Gatewaydenied = 'N';
string stringGateway = "Yes";
string stringGatewayDenied = "No";
string information;
string Newusername;
string Newpassword;
string Universalpassword;
string Universalusername;
printf("\n \t \n");
printf("\tThis is Dell login interference.....");
printf("\n");
printf("\t#################################\n");
printf("\t#################################\n");
printf("\n");
printf("\n");
printf(" Please inset your id and password in below user friendly interface.");
printf("\n");
printf("\n");
printf("Please type answer in Y and N");
printf("\n");
printf("Do you want the Dell's login user interfae: ");
Fdecision = GetChar();
if (Fdecision == Gateway)
{
printf("Do you want to create a new user. Answer in Yes or NO: ");
string userChoice = GetString();
printf("\n");
if (strcmp(stringGateway, userChoice) == 0)
{
printf("To create a New User Account.... Fill following boxes..\n");
printf("\n");
printf("username: ");
Newusername = GetString();
printf("password: ");
Newpassword = GetString();
printf("\n");
printf("Your personal textBook..:: ");
information = GetString();
printf("\n");
// Checks if it is opened..
if (accountsDatabase == NULL)
{
printf("Error opening file:\n");
}
else
{
fputs(Newusername, accountsDatabase);
fputs(Newpassword, accountsDatabase);
}
printf("Do you want to login.? Answer in Yes or No: ");
string LoginDecision = GetString();
if(strcmp(stringGateway, LoginDecision) == 0)
{
printf("Username: ");
string username = GetString();
printf("\n");
if (strcmp(Newusername, username) == 0)
{
printf("Password: ");
string password = GetString();
if (strcmp(Newpassword, Newpassword) == 0)
{
printf("\n");
printf("Confirming Identity.....\n");
printf("Identity Confirmed.....\n");
printf("\n");
printf("Do you want to reveal your sensitive information: ");
string secondDecision = GetString();
if (strcmp (stringGateway, secondDecision) == 0)
{
printf("\n");
printf("Enter password:: ");
string Currentpassword = GetString();
if (strcmp (Newpassword, Currentpassword) == 0)
{
printf("\n");
printf("%s\n", information);
printf("\n\n");
}
}
}
}
}
}
else if (strcmp(stringGatewayDenied, userChoice) == 0)
{
printf("\n");
printf("Username: ");
string username = GetString();
printf("\n");
// Checks if it is opened..
if (accountsDatabase == NULL)
{
printf("Error opening file:\n");
}
else
{
fgets(Universalusername, "%s", accountsDatabase);
if (strcmp(Universalusername, username) == 0)
{
printf("Password: ");
string password = GetString();
if (strcmp(Universalpassword, password) == 0)
{
printf("\n");
printf("Confirming Identity.....\n");
printf("Identity Confirmed.....\n");
printf("\n");
printf("Do you want to reveal your sensitive information: ");
string secondDecision = GetString();
if (strcmp (stringGateway, secondDecision) == 0)
{
printf("\n");
printf("Enter password:: ");
string Currentpassword = GetString();
if (strcmp (Universalpassword, Currentpassword) == 0)
{
printf("\n");
printf("%s\n", information);
printf("\n\n");
}
}
}
}
}
printf("Universalusername : %s", Universalusername);
}
else
{
printf("Take these security measures...\n");
printf("##############################");
printf("\n");
printf(" 1) You need specil previlage to access sensitive information...\n");
printf(" 2) Please run in a minute either alarm will be trigered..\n");
printf(" 3) Security camera are availabel, \n 4) run now.\n");
}
}
else if (Fdecision == Gatewaydenied)
{
printf("\n");
printf("You can get off from front door.\n");
printf("Don't LOok Back, it's not safe..\n'");
printf("What do you think? Can you cheat me? \n");
printf("No, you cannot!");
}
else
{
printf("\n");
printf("Please choose between Yes (Y) or No (N)\n");
printf("Not the full spelling but ony a single abbreviated letter..\n");
printf("Y or N..\n");
}
fclose(accountsDatabase);
}
string
- плохая идея дляtypedef
, потому что а) неясно, что вы имеете дело с указателем. б) В c нет строкового типа, понимание того, как строки представлены в c, имеет фундаментальное значение для любого программиста на C. 2. Это то, что имел в виду Торвальдс с более чем 3 уровнями отступов, довольно сложно понять ваш код без комментариев и с его текущей структурой. - person Iharob Al Asimi   schedule 14.11.2015fopen()
- еще одна очень плохая вещь в этом коде. - person Iharob Al Asimi   schedule 14.11.2015string
иTorvalds 3 levels of indentation
? я реально запутался!!! - person milevyo   schedule 28.11.2015