C 655 not golfed
Code creates weighted sum of chars for each string. If the difference is zero then they are equal, including 2 empty strings:
#include <stdio.h> #define N 100 #define P(x) printf(x) #define G(x) gets_s(x) void e(int x){ x ? P("equal\n") : P("not equal\n"); } int main() { char s[N], t[N];//words char *p = 0, *q = 0; int r = 0; //result 0=false int n=0, m=0; //weighted sums int i = 1; //char pos start at 1 if ((p=gets_s(s)) && (q=gets_s(t))) { while (*p) { n += i*(int)*p; m += i*(int)*q; i++; p++; q++; if (!(*q)){ break; } } if (!*p && !*q){ //both same length strings if (!(m - n)){ r = 1; } //weighted sums are equal }//else r=0, false=>not equal e(r); } else{ P("error\n"); } getchar(); }