作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试做一个滚动菜单。我的问题在于
GetAsyncKeyState(VK_RETURN)
我输入信息后,没有返回到我的菜单。它突然要求我输入另一个信息(这是无穷无尽的)。
我不确定它是否与 GetAsyncKeyState(VK_RETURN) 语句一起使用,因为每次我尝试输入最后一个信息(即“输入年份”)时,它都会返回到菜单,但会自动按 Enter 键“输入学生”选项。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<windows.h>
#include<iostream>
using namespace std;
typedef struct{
char fname[24],lname[16],mi,course[16];
int year;
unsigned long ID;
}studtype;
void getStudent(void);
void getHeader();
void readToFile(void);
// FILE * openFile(FILE *);
// void closeFile(FILE *);
// studtype *writeFile(studtype *,FILE *);
int main(void)
{
char* Menu[2];
Menu[0] = "Input Student";
Menu[1] = "Display Student";
int choice;
int pointer = 0;
while(true)
{
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
printf("Main Menu\n\n");
for (int i = 0; i < 2; ++i)
{
if (i == pointer)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
cout << Menu[i] << endl;
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << Menu[i] << endl;
}
}
while(true)
{
if (GetAsyncKeyState(VK_UP) != 0)
{
pointer -= 1;
if (pointer == -1)
{
pointer = 1;
}
break;
}
else if (GetAsyncKeyState(VK_DOWN) != 0)
{
pointer += 1;
if (pointer == 2)
{
pointer = 0;
}
break;
}
else if (GetAsyncKeyState(VK_RETURN) != 0)
{
switch (pointer)
{
case 0:
{
printf("\n\n");
getStudent();
} break;
case 1:
{
printf("\n\n");
getHeader();
readToFile();
Sleep(5000);
} break;
}
break;
}
} Sleep(150);
}
}
void getHeader()
{
printf("%-10s","ID");
printf("%-10s","FirstName");
printf("%-10s","LastName");
printf("%-20s","MiddleInitial");
printf("%-15s","Course");
printf("%-15s","Year");
printf("%-10s","-------");
printf("%-10s","---------");
printf("%-10s","--------");
printf("%-10s","----------");
printf("%-10s","-------");
printf("%-10s","---------");
printf("%10s","-------");
printf("%s"," ");
}
void getStudent(void)
{
studtype stud;
FILE * fp;
if(( fp = fopen("sample.txt","a"))!=NULL)
{
system("cls");
printf("Enter Student ID: ");
scanf("%d",&stud.ID);
printf("Enter FirstName: ");
fflush(stdin);
gets(stud.fname);
printf("Enter LastName: ");
fflush(stdin);
gets(stud.lname);
printf("Enter MI: ");
scanf("%c",&stud.mi);
printf("Enter Course: ");
fflush(stdin);
gets(stud.course);
printf("Enter Year: ");
scanf("%d",&stud.year);
fwrite(&stud,sizeof(studtype),1,fp);
fclose(fp);
}
}
void readToFile(void)
{
studtype stud;
FILE * fp;
if(( fp = fopen("sample.txt","r"))!=NULL)
{
while(fread(&stud,sizeof(studtype),1,fp))
{
printf("%-10d",stud.ID);
printf("%15s",stud.fname);
printf("%10s",stud.lname);
printf("%10c",stud.mi);
printf("%15s",stud.course);
printf("%10d",stud.year);
printf("%10s","");
}
fclose(fp);
}
}
问题出在哪里?
最佳答案
一般来说,混合使用 C++ 风格的流输入和输出、C 风格的 I/O、conio 风格的键盘 I/O 和系统调用屏幕 clr 并不是一个好主意。四种不同的东西不能保证一起发挥良好的作用。
关于c++ - GetAsyncKeyState(VK_RETURN)遭遇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24583802/
我正在尝试做一个滚动菜单。我的问题在于 GetAsyncKeyState(VK_RETURN) 我输入信息后,没有返回到我的菜单。它突然要求我输入另一个信息(这是无穷无尽的)。 我不确定它是否与 Ge
在 android 中创建 TreeView 的库非常好,AndroidTreeView . 这个库在我启用 proguard 之前工作正常,然后应用程序崩溃了。 注意:我有一个包含 5 个 frag
我在我的 grunt shell 中使用它: customers=LOAD 'hdfs://localhost:9000/pig_data_customers' USING PigStorage(',
我是一名优秀的程序员,十分优秀!