本站GitLab代码仓库(Building)
https://eqqie.cn:8099/ (装了服务器快要爆了,所以不一定开)
使用malloc创建结构体数组
#include<stdio.h>
#include<stdlib.h>
int main(){
struct book{
int a=1;// 4 [0,3]
char b='B'; // 1 [4]
short c=3; //2 [6,7]
// 8
} test;
struct book *p1;
struct book *p2=&test;
p1=(struct book *)malloc(10*sizeof(struct book));
//注意!!malloc创建的结构体数组虽然结构一样,但是并没有初始化的内容
//所以直接访问成员会得到内存上的数值
printf("value:\n");
(p1+1)->a=1;
//注意不是*p1->a=1,p1指向的是结构体地址,使用*取值符号是取不到值的
//使用->才能取到成员的值并且修改这个值
//(易错)
printf("%d\n",(p1+1)->a);
printf("%d\n",p2->a);
return 0;
}
带有输入检查的getchar
/*输入检查*/
void s_gets(char *buf, int len)
{
char ch;
int count;
/*字符串数组最后一个位置是len-1,需要预留出来以便添加\0*/
for(count = 0; count < len - 1; count++)
{
ch = getchar();
if(ch != '\n')
{
buf[count] = ch;
}
else //检测到换行符的时候替换为\0,并且结束输入
{
buf[count] = '\x00';
return;
}
}
buf[len-1] = '\x00'; //输入过长被截断后自动在行末添加\0
}
写题见到一个挺不错的输入检查
unsigned __int64 __fastcall get_input(__int64 ptr, __int64 len, char EOF)
{
char endchar; // [rsp+Ch] [rbp-34h]
char buf; // [rsp+2Fh] [rbp-11h]
unsigned __int64 i; // [rsp+30h] [rbp-10h]
ssize_t num; // [rsp+38h] [rbp-8h]
endchar = EOF;
for ( i = 0LL; len - 1 > i; ++i )
{
num = read(0, &buf, 1uLL);
if ( num <= 0 )
exit(-1);
if ( buf == endchar )
break;
*(_BYTE *)(i + ptr) = buf;
}
*(_BYTE *)(ptr + i) = 0;
return i;
}
汇编常用语句
LOOP语句
cx是寄存器,loop是通过控制寄存器数组控制循环次数
执行流程:
mov cx,100 ;数字代表循环的次数
标号:
执行体
loop 标号
mov ah,4ch ;程序结束时的标志
int 21
2019年8月15日 下午8:17 沙发
大佬牛逼
2019年10月6日 下午11:58 板凳
太强大了,先🐎后看