#include <stdio.h>
#include "string.h"
#include <windows.h>
#define N 5
typedef struct{
char num[10];
int fen;
}STR;
void fun(STR *s,char *xue,STR *h)
{
int i;
for(i=0;i<N;i++)
if((strcmp(s[i].num,xue))==0){
*h=s[i];
break;
}
else{
h->num[0]=0;//这一句和下面一句有问题,不知道怎么改了.
h->fen=-1;
}
}
CONSOLE_SCREEN_BUFFER_INFO sb_info;
void Cls()
{
HANDLE c_hstdout = CreateFile("CONOUT$",GENERIC_WRITE | GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
GetConsoleScreenBufferInfo(c_hstdout, &sb_info);
//char t_blank[81];
char* t_blank = new char[sb_info.dwSize.X + 1];
// memset(t_blank,0,81 * sizeof(char));
memset(t_blank,32,sb_info.dwSize.X * sizeof(char));
t_blank[sb_info.dwSize.X] = 0;
COORD c_l_s;
unsigned long Result=0;
for(int i = 0; i < sb_info.dwSize.Y; i++)
{
c_l_s.X = 0; c_l_s.Y = i;
WriteConsoleOutputCharacter(c_hstdout, t_blank, sb_info.dwSize.X, c_l_s, &Result);
WORD attr = FOREGROUND_RED |FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
FillConsoleOutputAttribute(c_hstdout, attr, sb_info.dwSize.X, c_l_s, NULL);
// ConWriteText(c_l_s.X, c_l_s.Y, t_blank, attr);
}
delete t_blank;
}
void main(){
STR s[N]={{"a001",65},{"a002",78},{"a003",89},{"a004",98},{"a005",23}},h;
char xue[10];
Cls();
printf("Input xue hao: ");
gets(xue);
fun(s,xue,&h);
printf("\nxue hao:%s,fen shu:%d\n",h.num,h.fen);
}
参考资料:这个是刚才题目的调试结果