Solved

Windows and Unix compatibility

Posted on 2003-11-12
12
473 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:expertyasin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9729858
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
 
LVL 1

Accepted Solution

by:
yahelb earned 20 total points
ID: 9729963
you've got:

_stricmp for strcasecmp
0
 

Author Comment

by:expertyasin
ID: 9730462
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9730886
>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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9732123

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
 
LVL 5

Expert Comment

by:g0rath
ID: 9732507
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 9733800

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
 
LVL 5

Expert Comment

by:g0rath
ID: 9734238
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10392245

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

sigh....

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question