Check whether one string is rotated version of other(Josh software programming test problem-2)

Write a program to accept two strings str1 and str2 and checks whether str2 is rotated version of str1.
Ex. Following are different values of str2 for given str1.
2-character left rotate
4-character left rotate
3-character right rotate

It seems to be bit difficult problem ,but it’s not actually. To solve this problem , We have to append first string to itself. And then check whether second string is present in first or not.

For example:
so append str1 to itself. Hence now str1=”softwaresoftware” . Now check str2 is present in str1 or not. Str2 is present in str1, hence str2 is rotated version of str1.

Note- You can not use strcat() function of string.h to concatenate a string to itself .Concatenation of string to itself using strcat() function is undefined behavior in C.

Solution using inbuilt  function of C.


Solution without using inbuilt functions

Josh Software programming test Problem 1

Leave comment if you have any problem with code.

About Gaurav Vichare

Hi , I am Gaurav : author of this blog , Software engineer and a Photoshop lover . You can connect me on LinkedIn, cirlce me on Google or follow on Twitter