我是一个刚刚自学c/c++的人
我使用的是VS2022
编译没有问题,运行时有BUG会报错
老
//加载头文件
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<ctime>
#include<direct.h>//获取当前文件所在位置的头文件
using namespace std;
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//全局变量定义
extern int JudgmentLoginD1 = 0;
extern int JudgmentLoginD2 = 0;
//Delay延时
void Delay(int time) {
clock_t now = clock();
while (clock() - now < time);
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//界面输出------登录菜单
void JCUIlogin1() {
printf("**********************************************\n");
printf("* *\n");
printf("* 1.Log in to your account << *\n");
printf("* 2.Sign up for an account *\n");
printf("* 3.EXIT *\n");
printf("* *\n");
printf("**********************************************\n");
return;
}
void JCUIlogin2() {
printf("**********************************************\n");
printf("* *\n");
printf("* 1.Log in to your account *\n");
printf("* 2.Sign up for an account << *\n");
printf("* 3.EXIT *\n");
printf("* *\n");
printf("**********************************************\n");
return;
}
void JCUIlogin3() {
printf("**********************************************\n");
printf("* *\n");
printf("* 1.Log in to your account *\n");
printf("* 2.Sign up for an account *\n");
printf("* 3.EXIT << *\n");
printf("* *\n");
printf("**********************************************\n");
return;
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//文本合成
void LoadText(int longe, char filename[30], char TheCurrentFileLocation[30]) {
//变量定义
char wenjian[256]="0";
_getcwd(wenjian, 256);
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//注册逻辑
void UIenroll() {
char path[100] = "0", User[100] = "0", password[100] = "0", rundl[100] = "0";
printf("Please enter your username(Enter EXIT to exit)$");
scanf_s("%s", &User,30);
printf("Please enter your password$");
scanf("%s", &password,30);
if (strcmp(User, "exit") == 0 || strcmp(User, "Exit") == 0 || strcmp(User, "EXIT") == 0)
{
JudgmentLoginD2 = 1;
return;
}
strcat(path, ">>system\\USER\\");
strcat(path, User);
strcat(path, ".User");
strcat(rundl, "echo ");
strcat(password, " h");
strcat(rundl, password);
strcat(rundl, " ");
strcat(rundl, path);
system(rundl);
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//登录逻辑
void UIligin() {
while (1)
{
int a = 1;//字符串长度
char User[100]="0", password[100]="0", temporary[100]="0", path[100]="0", JC[100]="0";
printf("Please enter a username(Enter EXIT to exit)$");
cin >> User;
printf("Please enter a password(Enter EXIT to exit)$");
cin >> password;
if (strcmp(User, "EXIT") == 0 || strcmp(User, "exit") == 0 || strcmp(User, "Exit") == 0) {
JudgmentLoginD1 = 1;
break;
}
strcat(path, "system\\USER");
strcat(temporary, User);
strcat(User, ".User");
strcat(path, User);
strcat(User, "\0");
a = sizeof(password);
FILE* fp1 = fopen(path, "r");
fgets(JC, a, fp1);
fclose(fp1);
if ((fp1 = fopen(path, "r")) == NULL) {
printf("The user does not exist");
Delay(1000);
system("cls");
}
else if (strcmp(JC, password) == 0) {
fclose(fp1);
JudgmentLoginD1 = 2;
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//UI逻辑
void UILG() {
//变量定义
int key = 0, pt = 1;
JCUIlogin1();
while (1)
{
//按键监听
key = _getch();
//回车逻辑
if (key == 13 && pt == 1)
{
system("cls");
UIligin();
if (JudgmentLoginD1 == 1) {
system("cls");
JCUIlogin1();
continue;
}
else if (JudgmentLoginD1 == 2) {
break;
}
}
if (key == 13 && pt == 2) {
system("cls");
UIenroll();
system("cls");
JCUIlogin2();
pt = 2;
continue;
}
if (key == 13 && pt == 3) {
exit(0);
}
//上下逻辑
if (key == 115 && pt == 1) {
pt = 2;
system("cls");
JCUIlogin2();
continue;
}
if (key == 115 && pt == 2) {
pt = 3;
system("cls");
JCUIlogin3();
continue;
}
if (key == 119 && pt == 3) {
pt = 2;
system("cls");
JCUIlogin2();
continue;
}
if (key == 119 && pt == 2) {
pt = 1;
system("cls");
JCUIlogin1();
continue;
}
}
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//主函数
int main() {
//判断文件夹
if (fopen("system\\USER\\JudgmentFile.dll", "r") == NULL) {
system("md system");
system("md system\\USER");
system("echo ""Complete instrumentation to generate data"" >> system\\USER\\JudgmentFile.dll");
system("cls");
}
//变量定义
char IdentifierOne[10] = "start";
UILG();
}
新
//加载头文件
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<ctime>
#include<direct.h>//获取当前文件所在位置的头文件
using namespace std;
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//全局变量定义
extern int JudgmentLoginD1 = 0;
extern int JudgmentLoginD2 = 0;
//Delay延时
void Delay(int time) {
clock_t now = clock();
while (clock() - now < time);
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//界面输出------登录菜单
void JCUIlogin1() {
printf("**********************************************\n");
printf("* *\n");
printf("* 1.Log in to your account << *\n");
printf("* 2.Sign up for an account *\n");
printf("* 3.EXIT *\n");
printf("* *\n");
printf("**********************************************\n");
return;
}
void JCUIlogin2() {
printf("**********************************************\n");
printf("* *\n");
printf("* 1.Log in to your account *\n");
printf("* 2.Sign up for an account << *\n");
printf("* 3.EXIT *\n");
printf("* *\n");
printf("**********************************************\n");
return;
}
void JCUIlogin3() {
printf("**********************************************\n");
printf("* *\n");
printf("* 1.Log in to your account *\n");
printf("* 2.Sign up for an account *\n");
printf("* 3.EXIT << *\n");
printf("* *\n");
printf("**********************************************\n");
return;
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//文本合成
void LoadText(int longe, char filename[30], char TheCurrentFileLocation[30]) {
//变量定义
char wenjian[256]="0";
_getcwd(wenjian, 256);
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//注册逻辑
void UIenroll() {
char path[100] = "0", User[100] = "0", password[100] = "0", rundl[100] = "0";
printf("Please enter your username(Enter EXIT to exit)$");
scanf_s("%s", &User,30);
printf("Please enter your password$");
scanf("%s", &password,30);
if (strcmp(User, "exit") == 0 || strcmp(User, "Exit") == 0 || strcmp(User, "EXIT") == 0)
{
JudgmentLoginD2 = 1;
return;
}
strcat(path, ">>system\\USER\\");
strcat(path, User);
strcat(path, ".User");
strcat(rundl, "echo ");
strcat(password, " h");
strcat(rundl, password);
strcat(rundl, " ");
strcat(rundl, path);
system(rundl);
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//登录逻辑
void UIligin() {
while (1)
{
int a = 1;//字符串长度
char User[100]="\0", password[100]="\0", temporary[100]="\0", path[100]="\0", JC[100]="\0";
printf("Please enter a username(Enter EXIT to exit)$");
cin >> User;
printf("Please enter a password(Enter EXIT to exit)$");
cin >> password;
if (strcmp(User, "EXIT") == 0 || strcmp(User, "exit") == 0 || strcmp(User, "Exit") == 0) {
JudgmentLoginD1 = 1;
break;
}
strcat(path, "system\\USER");
strcat(temporary, User);
strcat(User, ".User");
strcat(path, User);
strcat(User, "\0");
a = sizeof(password);
FILE* fp1 = fopen(path, "r");
fgets(JC, a, fp1);
fclose(fp1);
if ((fp1 = fopen(path, "r")) == NULL) {
printf("The user does not exist");
Delay(1000);
system("cls");
}
else if (strcmp(JC, password) == 0) {
fclose(fp1);
JudgmentLoginD1 = 2;
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//UI逻辑
void UILG() {
//变量定义
int key = 0, pt = 1;
JCUIlogin1();
while (1)
{
//按键监听
key = _getch();
//回车逻辑
if (key == 13 && pt == 1)
{
system("cls");
UIligin();
if (JudgmentLoginD1 == 1) {
system("cls");
JCUIlogin1();
continue;
}
else if (JudgmentLoginD1 == 2) {
break;
}
}
if (key == 13 && pt == 2) {
system("cls");
UIenroll();
system("cls");
JCUIlogin2();
pt = 2;
continue;
}
if (key == 13 && pt == 3) {
exit(0);
}
//上下逻辑
if (key == 115 && pt == 1) {
pt = 2;
system("cls");
JCUIlogin2();
continue;
}
if (key == 115 && pt == 2) {
pt = 3;
system("cls");
JCUIlogin3();
continue;
}
if (key == 119 && pt == 3) {
pt = 2;
system("cls");
JCUIlogin2();
continue;
}
if (key == 119 && pt == 2) {
pt = 1;
system("cls");
JCUIlogin1();
continue;
}
}
}
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------间隔线------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//主函数
int main() {
//判断文件夹
if (fopen("system\\USER\\JudgmentFile.dll", "r") == NULL) {
system("md system");
system("md system\\USER");
system("echo ""Complete instrumentation to generate data"" >> system\\USER\\JudgmentFile.dll");
system("cls");
}
//变量定义
char IdentifierOne[10] = "start";
UILG();
}
编译时没有问题运行时报错
有没有懂哥解答一下
【以下回答由 GPT 生成】
全局变量定义在代码中起到它们被声明的位置之前的任何地方都是有效的,并且可以被程序中的任何函数使用。在你提供的代码中,全局变量 JudgmentLoginD1
和 JudgmentLoginD2
被声明为 extern
,这意味着它们在其他文件中定义并且可以在当前文件中使用。全局变量的作用是在整个程序中共享数据。
根据你提供的问题描述,没有提供具体的报错内容。请提供更加详细的报错信息。
根据你的问题描述,没有提到是否尝试过调试该代码以了解报错原因。调试是解决代码问题的一种重要方式。你可以使用VS2022中的调试工具,设置断点和观察变量的值,来逐步执行代码,找出报错产生的原因。
根据你的问题描述,没有提到是否尝试过搜索相关问题的解决方案。当遇到问题时,搜索引擎是一个很好的资源,有时候可能会有其他人遇到过类似的问题,并提供了解决方案。尝试搜索一下你遇到的具体报错信息,可能会找到一些有用的解决方案。
根据你的问题描述,没有提到是否尝试过对代码进行逐行排查以确定问题所在。在遇到问题时,逐行排查代码是一种有效的方法,可以帮助你找到可能引起错误的部分。你可以通过注释掉一些代码块,逐渐缩小问题所在的范围,直到找到造成报错的具体代码。
根据你的描述,没有提供足够的错误信息或问题复现步骤。请提供更多详细信息,例如报错信息、错误堆栈跟踪等。这样才能更好地帮助你解决问题。
根据你的问题描述,没有提到是否遇到其他问题。如果你还有其他问题,可以一并提出来,我们将尽力解答。
根据你的问题描述,没有提到对解决问题的期望或具体要求。如果你对解决问题有特定的期望或要求,请提供更多细节,以便我们更好地帮助你。
【相关推荐】
看提示应该是文件读取错误
字符串初始化用 char path[100] = 0或char path[100] = "\0"