Пример #1
0
Файл: main.c Проект: gchatzip/C
int main(void){
  /*holding memory dynamically */ 
  char *s1 = (char *)malloc(100*sizeof(char));
  char *s2 = (char *)malloc(100*sizeof(char));
  char *cp = (char *)malloc(100*sizeof(char));
  /*asking from the user to give us all the things we need to call functions */
  printf("Give the string :");
  gets(s1);
  printf("Give the string :");
  gets(s2);
  printf("\n");
  printf("Give the number n of bytes:");
  scanf("%d",&num);
  /*calling all the functions */
  printf("mystr: %d\n",ms_length(s1));
  printf("mystr: %s\n",ms_copy(s1,s2));
  printf("mystr: %s\n",ms_concat(s1,s2));
  printf("mystr: %d\n", ms_compare(s1,s2));
  printf("mystr: %s\n", ms_search(s1,s2));
  printf("mystr: %s\n", ms_ncopy(s1,s2,num));  
  printf("mystr: %s\n", ms_nconcat(s1,s2,num));
  printf("mystr: %d\n", ms_ncompare(s1,s2,num));
  /*freeing the dynamically holded memory */ 
  free(s1);
  free(s2);
  free(cp);

  return 0;
  

}
Пример #2
0
static int ms_lower( m_sort *m, int from, int to, int val ) {
  	int len = to - from, half, mid;
  	while( len > 0 ) {
  		half = len>>1;
		mid = from + half;
		if( ms_compare(m, mid, val) < 0 ) {
    		from = mid+1;
    		len = len - half -1;
   		} else
   			len = half;
  	}
	return from;
}
Пример #3
0
static int ms_upper( m_sort *m, int from, int to, int val ) {
	int len = to - from, half, mid;
	while( len > 0 ) {
		half = len>>1;
		mid = from + half;
		if( ms_compare(m, val, mid) < 0 )
			len = half;
		else {
			from = mid+1;
			len = len - half -1;
		}
	}
	return from;
}
Пример #4
0
static void ms_do_merge( m_sort *m, int from, int pivot, int to, int len1, int len2 ) {
	int first_cut, second_cut, len11, len22, new_mid;
	if( len1 == 0 || len2==0 )
		return;
	if( len1+len2 == 2 ) {
		if( ms_compare(m, pivot, from) < 0 )
			ms_swap(m, pivot, from);
   		return;
  	}
	if (len1 > len2) {
		len11=len1>>1;
		first_cut = from + len11;
		second_cut = ms_lower(m, pivot, to, first_cut);
		len22 = second_cut - pivot;
	} else {