• C

Windows and Unix compatibility

Hi,

One of my application in unix , i have used isblank("") and strcasecmp() functions .
but in windows , they are not working . Anybody knows what are the equvalent functions
in windows.

Thanks in advance
expertyasinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
dont know windows equivalent but you can code them yourself

int isblank ( char * in )
{
        if ( *in == ' ' || *in == '\t' || *in == '\n' )
                   return 1;
        else
                   return 0;
}

likewise, in the implementation of if toupper/tolower are available on windows, you can convert both strings to the same case and then use strcmp()
0
yahelbCommented:
you've got:

_stricmp for strcasecmp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
expertyasinAuthor Commented:
Hi guys,

Both answers are useful to me .

Hi yahelb ,

  Can I use this stricmp() function in unix also . Is it compatible with Unix or i need to identify the OS and based on the code those two functions ?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

GloomyFriarCommented:
>Can I use this stricmp() function in unix also .
No. All the functions with name started with '_' are Microsoft specific.

There is no ANSI equivalent for stricmp as far as I know.
0
Kent OlsenDBACommented:

Hi expertyasin,

All if the isxxxxx() macros are defined in ctype.h.  Include that header file and isblank() will work just fine.


strcasecmp() appears to be a proprietary API.  If the purpose of the function is to compare two strings without regard to case ("STRing1" will match "string1") then use the strncmp() function.  strncmp() is portable and should be supported on all platforms.


Good Luck,
Kent
0
g0rathCommented:
when writing portable code you'll have to some odd hacks such as:

#ifdef __linux__
#include <unistd.h>
#end if

#ifdef WIN32
#define strcasecmp stricmp
#endif

#ifdef OTHER_OS
#define strcasecmp my_strcasecmp
#include "my_strcasecmp.h"
#endif

so in your code you just write once

strcasecmp(string1, string2);
0
Kent OlsenDBACommented:

stricmp() is the "case insensitive" string compare used by Micro$oft and Borland.  strncmp() is the equivalent in unix/linux.

I know that Borland supports both stricmp() and strncmp() but I don't know about MS.


Since your original question was unix related, change all occurrences of "strcasecmp" to "strncmp" and you'll be fine.

Or take the approach suggested by g0rath and define an equivalence:

#define strcasecmp strncmp


The second suggestion is the "quick and dirty" way to get past the error, but it works just fine.  You might as well get used to typing strncmp() so please seriously consider changing "strcasecmp" to "strncmp".


Kent
0
g0rathCommented:
uh according to the man page....unix side

// Both case insenstive, but one you specify the first N bytes
int  strncasecmp(const  char  * s1,  const  char  * s2,  size_t  n);
int  strcasecmp(const  char  * s1,  const  char  * s2);

// Both Lexical, but one you specify the first N bytes
int  strncmp(const  char  * s1,  const  char  * s2,  size_t  n);
int  strcmp(const  char  * s1,  const  char  * s2);


strcasecmp != strncmp under unix
but windows changes things to be not quite as compatible

Windows....
MSVC++

Perform a lowercase comparison of strings
int _stricmp( const char *string1, const char *string2 );

Compare characters of two strings without regard to case.
int _strnicmp( const char *string1, const char *string2, size_t count );

Lexical comparison
int strncmp( const char *string1, const char *string2, size_t count );


strcasecmp(unix) != strncmp(msvc++) ... now that my be true about Borland...but just be aware when comparing
0
Kent OlsenDBACommented:

Man.... where was head?  I meant stricmp() and strcmpi()....

sigh....

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.