K&R——第五章 指针与数组

#include <stdio.h>

#define maxsize 5000

char buf[maxsize];
char *head = buf;

char *new(int size)
{
	//分配元素字长
	
	//可用内存分配完毕
	if (maxsize - (buf - head) < size) 
		return 0;
	head += size;
	return head - size;
}

int *arr;
int *arr2;
char *str;

int main()
{
	arr = new(3 * sizeof(int));
	arr2 = new(3 * sizeof(int));
	str = new(10 * sizeof(char));
	
	for (int i=0;i<3;i++)
		scanf("%d",&arr[i]);
	for (int i=0;i<3;i++)
		scanf("%d",&arr2[i]);
	
	scanf("%s",str);
	
	for (int i=0;i<6;i++)
		printf("%d\n",arr[i]);
	
	printf("%s\n",str);
}

  

posted on 2014-10-09 20:58  杰斯特丹第  阅读(121)  评论(0编辑  收藏  举报

导航