Monday, November 29, 2021

Strcmp implementation by self, while mein dhyan de do conditions par check kar raha hai

 #include<stdio.h>
int fnCmp(char* str1, char* str2) {
    while( (*str1 != '\0' && *str2 != '\0') && (*str1 == *str2)) {
        str1++;
        str2++;
    }
    if(*str1 == *str2)
       return 0;
    else
       return *str1 - *str2;
}
int main() {
    char str1[] = "abc";
    char str2[] = "abc";
    int x = fnCmp(str1, str2);
    if(x == 0) {
        printf("Strings Are Same");
    } else {
        printf("Strings Are not Same");
    }
    return 0;
}

No comments:

Post a Comment

Priority queue deleting elements after ascending inputs Gaand Fadd

 using namespace std; #include<iostream> #define N 5 class pq { public:     int* arr;     int front;     int rear;     pq() {         ...