Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- #include <string.h>
- // aab
- // aba <- OK
- // abb
- // aab <- WRONG
- int cmpr(char *str1, char *str2) {
- if (str1 == NULL || str2 == NULL) {
- return 0;
- }
- //declarations and initializations of 26-elements arrays,
- //every single alphabetic character with one index assigned
- int tab1[26] = {0}, tab2[26] = {0};
- int i = 0, j = 0;
- //incrementation of specific array's index for str1
- for (; *(str1 + i) != '\0'; ++i) {
- tab1[*(str1 + i) - 'a']++;
- }
- //incrementation of specific array's index for str2
- for (; *(str2 + j) != '\0'; ++j) {
- tab2[*(str2 + j) - 'a']++;
- }
- //validation of both arrays length and memory areas
- if (i == j) {
- if (!memcmp(tab1, tab2, sizeof(tab1))) {
- return 1;
- }
- }
- return 0;
- }
- int main() {
- printf("%d\n", cmpr("abcdef", "abcfed"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement