This C Program determines if the two entered strings are circular permutation of another string. Eg: yzx is a circular permutation of xyz but not zyx.
Here is a source code of the C program to determine if the two entered string are a circular permutation of one another. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Determine if One String is a Circular Permutation of
* Another String
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define CHAR_SIZE 26
void alphacheck(char *, int []);
void create(char [], char [], int[]);
int main()
{
char str1[50], str2[50];
int a1[CHAR_SIZE] = {0};
char str2_rem[50];
printf("Enter string1: ");
scanf("%s", str1);
printf("Enter string2: ");
scanf("%s", str2);
alphacheck(str1, a1);
create(str2_rem, str2, a1);
printf("On removing characters from second string we get: %s\n", str2_rem);
return 0;
}
void alphacheck(char *str, int a[])
{
int i, index;
for (i = 0; i < strlen(str); i++)
{
str[i] = tolower(str[i]);
index = str[i] - 'a';
if (!a[index])
{
a[index] = 1;
}
}
printf("\n");
}
void create(char str_rem[], char str[], int list[])
{
int i, j = 0, index;
for (i = 0; i < strlen(str); i++)
{
index = str[i] - 'a';
if (!list[index])
{
str_rem[j++] = str[i];
}
}
str_rem[j] = '\0';
}
$ gcc circularpermu.c $ ./a.out Enter string 1: abcd Enter string 2: dabc abcd & dabc are circular permutation of each other.
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at programming examples on all topics, go to C Programming Examples.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Watch Advanced C Programming Videos
- Buy C Books
- Apply for C Internship
- Practice BCA MCQs
- Apply for Computer Science Internship