P
Pedro Graca
I wrote a pair of functions to make a string all uppercase or
lowercase.
The functions call a helper static function to do the conversion
including the address of toupper() or tolower() in the parameters.
My questions is:
Does the Standard allow toupper() or tolower() to be implemented as a
macro?
(Unlike for getc(), my documentation doesn't say they can be
implemented as macros)
To be on the safe side, should I add
#ifdef tolower
/* alternate version */
#else
/* my version */
#endif
-----------------------------------------------
This is the code I have:
#include <ctype.h>
#include <stddef.h>
static char *chg_str(char *destin, char *source, size_t n, int(f)
(int)) {
char *d = destin;
while (--n && *source) {
*destin = f(*source);
++source;
++destin;
}
*destin = 0;
return d;
}
char *lo_str(char *destin, char *source, size_t n) {
if (!source || !destin) return NULL;
if (!n) return destin;
return chg_str(destin, source, n, tolower);
}
lowercase.
The functions call a helper static function to do the conversion
including the address of toupper() or tolower() in the parameters.
My questions is:
Does the Standard allow toupper() or tolower() to be implemented as a
macro?
(Unlike for getc(), my documentation doesn't say they can be
implemented as macros)
To be on the safe side, should I add
#ifdef tolower
/* alternate version */
#else
/* my version */
#endif
-----------------------------------------------
This is the code I have:
#include <ctype.h>
#include <stddef.h>
static char *chg_str(char *destin, char *source, size_t n, int(f)
(int)) {
char *d = destin;
while (--n && *source) {
*destin = f(*source);
++source;
++destin;
}
*destin = 0;
return d;
}
char *lo_str(char *destin, char *source, size_t n) {
if (!source || !destin) return NULL;
if (!n) return destin;
return chg_str(destin, source, n, tolower);
}