0

Written in pure C..

But I have included string.h as:

#include <string.h>     // for strnlen
#include <stdlib.h>     // for _countof, _itoa fns, _MAX_COUNT macros  
#include <conio.h>      // for  _getch  
#include <process.h>    // for system  
#include <io.h>         // for findfirst  
#include <locale.h>  

called here:

if( argc != 2 )   {
  printf("Usage: extension .001 or .alm only\n");
  return(0);   
}
else printf("Read %d %s\n",argc, argv[1]);


if( !_getcwd((char *)cdir, sizeof(cdir)))    {  
  printf("\n ! ERROR ! obtaining current disc directory!");  
  printf("\n .. any key ..");  
  _getch();  
  exit(-1);  
}
printf("\n Directory: %s\n", cdir);

if(!_stricmp(argv[1],"alm"))
  sprintf(csrch,"*.alm");  
else 
  sprintf(csrch,"*.001");

So why the error/warning?

wimh
  • 15,072
  • 6
  • 47
  • 98
P.Holmes
  • 19
  • 5
  • Hmm, except I am using Windows. – P.Holmes May 27 '19 at 15:14
  • 1
    Possible duplicate of [warning: incompatible implicit declaration of built-in function ‘xyz’](https://stackoverflow.com/questions/977233/warning-incompatible-implicit-declaration-of-built-in-function-xyz) – wimh May 27 '19 at 17:30
  • Possible duplicate of [undefined reference to stricmp](https://stackoverflow.com/questions/5918697/undefined-reference-to-stricmp) – John Szakmeister May 27 '19 at 17:40
  • `stricmp` is not portable. Perhaps you want to use `strcasecmp()` from strings.h instead? – John Szakmeister May 27 '19 at 17:41

1 Answers1

0

Maybe you could manually convert the strings to all lowercase and then use strcmp?

int stricmp(const char *string1, const char *string2) {
    char* tmp1 = malloc(sizeof(string1));
    char* tmp2 = malloc(sizeof(string2));

    strcpy(tmp1, string1);
    strcpy(tmp2, string2);

    for (int i = 0; i < strlen(tmp1); i++)
        tmp1[i] = tolower(tmp1[i]);

    for (int i = 0; i < strlen(tmp2); i++)
        tmp2[i] = tolower(tmp2[i]);

    int res = strcmp(tmp1, tmp2);

    free(tmp1);
    free(tmp2);

    return res;
}
Tretorn
  • 365
  • 1
  • 16
  • FYI, I just ran the program with the two warnings and it seems to work fine. So God knows why or what the warnings are issued. – P.Holmes May 29 '19 at 08:18