EmbLogic's Blog

Allocation Test Function.

// Function To allocate bytes .
// Test function for writing write operation.
#include<stdio.h>
#include<stdlib.h>
#define SIZE 1000
char arr[SIZE];
char *p=arr;

char * allocate(unsigned char  );
char * allocate(unsigned char j)
{
if(arr+SIZE-p>j)
{
p=p+j;
return p-j;
}
else
{
printf(“Error in size\n”);
return NULL;
}
}
int main()
{
int *j;
char *l;
j=(int *)allocate(sizeof(int));
if(!j)
printf(“Error\n”);
*j=67;
l=(char *)allocate(sizeof(char));
*l=77;
printf(“%d %d\n”,*j,sizeof(*l));
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>