大家都知道scanf()遇到空格后就会结束 原因是底层函数是这么实现的
那现在从底层调用 不调用scanf()
源码:
#include <windows.h>
#include<iostream>
using namespace std;
_ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned);
#ifdef __cplusplus
extern "C"
#endif
FILE* __cdecl __iob_func(unsigned i) {
return __acrt_iob_func(i);
}
// 全局变量
char g_szId[120] = { " i love this game\n\n" };
#pragma comment(lib,"user32.lib")
int main()
{
// 局部变量
char szBuf[120];
printf("please input password: ");
scanf_s("%s", szBuf, 120);
char* p = *(char**)((int)__iob_func(0) + 4); //取缓冲区中的值 __iob_func(0)输入
//__iob_func(1)输出 __iob_func(2)错误
printf("%s\n", szBuf);
printf("%s", p);
if (strcmp(p, g_szId) == 0)
{
printf("It's Right\n");
}
else
{
printf("It's Err \n");
}
system("pause");
return 0;
}
//vc6.0版
//#include "stdio.h"
//#include <windows.h>
//// 全局变量
//char g_szId[120] = { " i love this game\n\n" };
//#pragma comment(lib,"user32.lib")
//
//int _tmain(int argc, _TCHAR* argv[])
//{
// // 局部变量
// char szBuf[120];
// printf("please input password: ");
// scanf_s("%s", szBuf, 120);
//
// char* p = *(char**)((int)__iob_func() + 8);
// if (strcmp(p, g_szId) == 0)
// {
// printf("It's Right \n");
// }
// else
// {
// printf("It's Err \n");
// }
// system("pause");
//
// return 0;
//}
为什么打那么多呢 其它底层不管你打什么它都保存在那
用途优化下可以作为登录密码(我本来就是逆出来的)