Esempio n. 1
0
// Rotate arjun by 2 is junar
// Reverse arjun -> nujra
// Reverse "nuj" and "ra"
void rotate_str_left2(char * str, unsigned int k) {

  unsigned int len = my_strlen(str);

  if (!len)
    return;

  k = k % len;

  if (!k)
    return;

  k = (len - k) - 1;
  string_reverse1(str, 0, len - 1);
  string_reverse1(str, 0, k);
  string_reverse1(str, k + 1, len - 1);
}
Esempio n. 2
0
void main(){
  char val[256];
  printf("Enter a string: \n");
  fgets(val, 256, stdin);
  /* First implementation */  
  string_reverse1(val);
  /* Second implementation */
  printf("2nd implementation - Reversed string: %s\n\n", string_reverse2(val)); 
  system("pause"); 
}  
int main() {

	// Testing 1st Reverse Method (Inplace Reverse Method)
	char str1 [] = "Hello1";
	string_reverse1(str1);
	printf("%s\n" , str1);

	// Testing 2nd Reverse Method (Copy Reverse Method)
	char str2 [] = "Hello2";
	char * res = string_reverse2(str2);
	printf("%s\n" , res);
	return 0;
}