3

when compiling in VS i get no error but with gcc i get the following:

warning: format ‘%Lf’ expects argument of type ‘long double *’, but argument 2 has type ‘double *’ [-Wformat=]
  scanf("%Lf",&checkprice);
  ^
/tmp/cch8NUeU.o: In function `main':
test.c:(.text+0x8e1): undefined reference to `stricmp'
collect2: error: ld returned 1 exit status

I guess this is normal. How can i fix it in gcc?

falsobuio
  • 93
  • 1
  • 10
  • Declare `checkprice` as a `long double`? And `stricmp` is not a standard function. I think you need `strcasecmp` for POSIX systems. – Fred Larson Jan 27 '15 at 21:21
  • 2
    I dunno if there is a portable `stricmp`. It's `strcasecmp` in POSIX, but that's ``, not ``. You may need to wrap this in your own platform agnostic function with some `#ifdefs` to select either `strcasecmp` or `stricmp`. – Brian McFarland Jan 27 '15 at 21:24
  • "%Lf" --> "%lf" this indeed worked.. – falsobuio Jan 27 '15 at 21:28
  • Oh, and doesn't VS compiler warn you about the `scanf()` specifier? does it have warnings turned on? The other function could be solved with a `#ifdef` as suggested in other comments. – Iharob Al Asimi Jan 27 '15 at 21:29
  • strcasecmp also did the trick with these libraries only: #include #include – falsobuio Jan 27 '15 at 21:33
  • Possible duplicate of [error C3861: 'strcasecmp': identifier not found in visual studio 2008?](https://stackoverflow.com/questions/3694723/error-c3861-strcasecmp-identifier-not-found-in-visual-studio-2008) – iammilind Oct 19 '19 at 03:53

1 Answers1

5

stricmp() is not a standard function, though there is a POSIX equivalent strcasecmp() so for your code to compile seamlessly with both compilers you can add something like this

#ifdef __GNUC__
#define _stricmp strcasecmp
#endif

and use _stricmp() since stricmp() was deprecated.

Also fix the scanf() format specifier, or change the destination variable type to long double.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • thanks! everything worked out! i did not quite catch the part "deprecated", why should i create a function _stricmp (with the underscore). – falsobuio Jan 27 '15 at 21:59
  • @falsobuio Read in the link, those functions are not recommended in new code. They still work primarily for compatibility with older code. – Iharob Al Asimi Jan 27 '15 at 22:15