示例#1
0
// Used when the current block needs to grow and there are no
// adjacent free blocks large enough to grow into. Instead, a new block 
// will be allocated and moved into. Then the orginal block will be freed
void *reallocIntoCompletelyNewBlock(header *headerPointer, uint32_t size) {
   void *block = myMalloc(size);
   myMemmove(block, headerPointer + 1, headerPointer->size);
   myFree(headerPointer + 1);

   return block;
}
示例#2
0
// Used for the senario where the previous block is free.
// It will add itself to the previous block, move the data
// to the previous block, and then call reallocFromTooBig(...)
void reallocIntoPreviousHeader(header *headerBefore, uint32_t size) {
   header *temp = headerBefore->next->next;

   headerBefore->size += headerSize + headerBefore->next->size;
   
   myMemmove(headerBefore + 1, 
    headerBefore->next + 1, headerBefore->next->size);
   
   headerBefore->next = temp;

   reallocFromTooBig(headerBefore, size);
}
int _tmain(int argc, _TCHAR* argv[])
{
	int c[10] = { 1,2,3,4,5,6,7,8,9,10 };
	int d[10];

	myMemcpy( d, c, sizeof( int )*10 );
	outputArray( c, 10 );
	outputArray( d, 10 );

	printf( "%d\n", myMemcmp( c, d, sizeof( int )*10 ) );

	myMemmove( c, &c[2], sizeof( int )*8 );
	outputArray( c, 10 );

	myMemmove( &c[2], c, sizeof( int )*8 );
	outputArray( c, 10 );

	myMemset( d, 0, sizeof( int )*10 );
	outputArray( d, 10 );

	char a[100] = "123456789";
	char b[100] = "abcdefghijklmn";

	printf( "%d\n", myStrlen( a ) );
	printf( "%d\n", myStrlen( b ) );

	printf( "%s\n", myStrcat( b, a ) );
	//printf( "%s\n", myStrcat( a, &a[2] ) );
	//printf( "%s\n", myStrcat( &a[2], a ) );
	printf( "%s\n", a );
	printf( "%d\n", myStrcmp( b, a ) );
	printf( "%s\n", myStrcpy( b, a ) );
	printf( "%s\n", myStrmove( a, &a[3] ) );
	printf( "%s\n", myStrmove( &a[4], a ) );
	printf( "%s\n", a );
	
	return 0;
}
int main(){
  char stra[50] = {0};
  char strb[50] = {0};
  char strc[50] = {0};
  sprintf(stra,"bbeeffABABcdfe");
  sprintf(strb,"AB");
  sprintf(strc,"ab");
  const char * str;
  //strstr
  if(NULL != (str = myStrstr(stra,strb))){
	printf("The str of %s in %s is %s\n",strb,stra,str);
  }else{
	printf("The %s is not in %s\n",strb,stra);
  }
  if(NULL != (str = myStrstr(stra,strc))){
	printf("The str of %s in %s is %s\n",strc,stra,str);
  }else{
	printf("The %s is not in %s\n",strc,stra);
  }

  //firstSingleChar
  printf("The firstSingleChar of %s is %c\n",stra,firstSingleChar(stra));

  //myStrcpy
  printf("The copy of %s is %s\n",stra,myStrcpy(strb,stra));

  //myStrtok
  char strd[] = "now # is the time for all # good men to come to the # aid of their country";
  char delims[] = "#";
  char *result = NULL;
  result = myStrtok( strd, delims );
  while( result != NULL ) {
	printf( "result is \"%s\"\n", result );
	result = myStrtok( NULL, delims );
  }
  printf("After myStrtok the str is %s \n",strd);
  char stre[] = "abcdefghijklmn";
  printf("Before the str is %s \n",stre);
  myMemmove(stre,stre + 3,8);
  printf("After memmove the str is %s \n",stre);
  return 0;
}