Given two strings, check whether one string is a string rotation of another

Given two strings, check whether one string is a string rotation of another


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(char *s,char *v)
{
 while(*s && (*s==*v))
  s++,v++;
 return (*s-*v);
}

void rotate(char *s,int n,int r)
{
 int i;
 char c;
 c=*s;
 for(i=0;i<n-1;i++)
 {
  *(s+i)=*(s+i+1);
 }
 *(s+n-1)=c;
}

int length(char *s)
{
 int len=0;
 while(*s)
 {
  len++;
  s++;
 }
 return len;
}

int main(void) {
 char *s;
 char *v;
 int n,flag=0,i;
 s=(char*)malloc(sizeof(char)*1000);
 v=(char*)malloc(sizeof(char)*1000);
 scanf("%s",s);
 scanf("%s",v);
 //rotate(s,strlen(s),1);
 //printf("%s",s);
 n=length(s);
 for(i=0;i<n;i++)
 {
  rotate(s,n,1);
  if(compare(s,v)==0)
   flag=1;
 }
 //printf("length=%d\n",n);
 if(flag)
  printf("YES");
 else
  printf("NO");
 return 0;
}