I am making a user defined function of strcmp() in c.
#include <stdio.h>
#include <string.h>
int la,lb; // la and lb for length of 2 strings
int scompare(char [],char []);
int main() {
char a[50],b[50]; // a and b are 2 strings
printf("Enter 2 strings \n");
gets(a);
gets(b);
la =strlen(a);
lb =strlen(b);
printf("%d",scompare(a,b));
}
int scompare(char a[la],char b[lb])
{
for(int i=0 ;i<max(la,lb);i++)
{ // loop for comparing characters of 2 strings
// here in vs code it is showing error --->
// warning: implicit declaration of function 'max' [-Wimplicit-function-declaration]
for(int i=0 ;i<max(la,lb);i++)
int k = a[i]-b[i];// k is the sum of ascii of characters of a and b
if(k!=0 &&toupper(a[i])==toupper(b[i]))
return (k>0)?1:-1;
// other error is showing here in function toupper ---> warning: implicit declaration of function 'toupper' [-Wimplicit-function-declaration]
if(k!=0 &&toupper(a[i])==toupper(b[i]))
else if(k!=0)
return k;
}
return 0;
}