代码拉取完成,页面将自动刷新
#include <stdlib.h>
#include <stdio.h>
#include "extmem.h"
int main1(int argc, char **argv)
{
Buffer buf; /* A buffer */
unsigned char *blk; /* A pointer to a block */
int i = 0;
/* Initialize the buffer */
if (!initBuffer(520, 64, &buf))
{
perror("Buffer Initialization Failed!\n");
return -1;
}
/* Get a new block in the buffer */
blk = getNewBlockInBuffer(&buf);
/* Fill data into the block */
for (i = 0; i < 8; i++)
*(blk + i) = 'a' + i;
/* Write the block to the hard disk */
if (writeBlockToDisk(blk, 8888, &buf) != 0)
{
perror("Writing Block Failed!\n");
return -1;
}
/* Read the block from the hard disk */
if ((blk = readBlockFromDisk(1, &buf)) == NULL)
{
perror("Reading Block Failed!\n");
return -1;
}
/* Process the data in the block */
int X = -1;
int Y = -1;
int addr = -1;
char str[5];
printf("block 1:\n");
for (i = 0; i < 7; i++) //一个blk存7个元组加一个地址
{
for (int k = 0; k < 4; k++)
{
str[k] = *(blk + i*8 + k);
}
X = atoi(str); ;
for (int k = 0; k < 4; k++)
{
str[k] = *(blk + i*8 + 4 + k);
}
Y = atoi(str);
printf("(%d, %d) ", X, Y);
}
for (int k = 0; k < 4; k++)
{
str[k] = *(blk + i*8 + k);
}
addr = atoi(str);
printf("\nnext address = %d \n", addr);
printf("\n");
printf("IO's is %ld\n", buf.numIO); /* Check the number of IO's */
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。