using 'int char' with #define's variables.
Hi All,
A function that has a prototype of:
char * strrchr( char * str, int ch );
It takes a character as an int in that second param.
I am having trouble using it with a #define's VAR.
---
#define DIRMARK "/"
...
char * filename = strrchr(path, DIRMARK); fprintf(stderr, "debug: filename = %s\n", filename);
---
gcc complains:
warning: passing arg 2 of `strrchr' makes integer from pointer without a cast
It compiles, but doesn't seem to work right:
debug: filename = (null)
Any suggestions?
- Nick
----- Original Message -----
From: "Nick Jennings" <[email protected]>
To: <[email protected]>
Sent: Sunday, September 01, 2002 6:35 PM
Subject: using 'int char' with #define's variables.
Quoted 4 lines
Hi All,
A function that has a prototype of:
Quoted 8 lines
char *
strrchr( char * str, int ch );It takes a character as an int in that second param.
I am having trouble using it with a #define's VAR.
---
#define DIRMARK "/"
That's a string (i.e., a char*), not a char.
Double quotes give you a string, single quotes give you a char.
/* This is a pointer to a null-terminated string of characters */ #define DIRMARK "/"
/* This is a single char */
#define DIRMARK '/'
Quoted 2 lines
gcc complains:
warning: passing arg 2 of `strrchr' makes integer from pointer without a cast
...which is exactly what's happening. You're passing a char* where it expects an int.
--Adam
Quoted 4 lines · Nick Jennings
char *
strrchr( char * str, int ch );It takes a character as an int in that second param.
Quoted 8 lines
I am having trouble using it with a #define's VAR.
---
#define DIRMARK "/"...
char * filename =
strrchr(path, DIRMARK);
Your #define is of type array of char, not a plain chiar. If you were to define it as
#define DIRMARK '/'
it would work better.
(note single-quote instead of double-quote)