Created
August 7, 2021 15:47
-
-
Save DBJDBJ/23b3aef0c3bbb252e870c964a9794cd8 to your computer and use it in GitHub Desktop.
DBJ ISO C STRING COMPARE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------- | |
// (c) 2021 by [email protected] | |
// https://dbj.org/license_dbj | |
// https://godbolt.org/z/vaMMrvM85 | |
// ---------------------------------------------- | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
#if __STDC_VERSION__ < 199901L | |
#error Please use C99 or better | |
#endif | |
// ---------------------------------------------- | |
#define P(F, X) printf("\n%4d: %32s: " F, __LINE__, #X, (X)) | |
// ---------------------------------------------- | |
bool dbj_strcmp(const int N, const int M, const char L[static N], | |
const char R[static M]) | |
{ | |
if (N == M) | |
return ! strcmp(L, R); | |
return false ; | |
} | |
static int test_dbj_strcmp( | |
char const ASTR[static 1], char const BSTR[static 1]) { | |
return dbj_strcmp( | |
strlen(ASTR), | |
strlen(BSTR), ASTR, BSTR | |
); | |
} | |
////////////////////////////////////////////////// | |
/// | |
int main(void) { | |
P("%d", test_dbj_strcmp("A", "VVV")); | |
P("%d", test_dbj_strcmp("A", "A")); | |
P("%d", test_dbj_strcmp("V", "A")); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am sure you can package this as a stand-alone executable. Just please respect the license.