Connecting Tech Pros Worldwide Forums | Help | Site Map

Q/Confused

Joe Cipale
Guest
 
Posts: n/a
#1: Jul 22 '05
I am trying to parse a data entry in a procedure. The procedure will
parse a data string on either a '/' or a ':'. My proceudre is delcared
as follows:
void chr_pad(char dte_str[16], char chr_tok)

The usage is:
chr_pad(dte_str, '/');

Within the code, I take advantage of the var 'chr_tok' in this manner:
strcpy(f1, strtok(dte_str, chr_tok));
strcpy(f2, strtok(NULL, chr_tok));
strcpy(f3, strtok(NULL, chr_tok));

When I attempt to compile the code, I get the following errors:
misc.cpp: In function `void chr_pad(char *, char)':
misc.cpp:360: passing `char' to argument 2 of `strtok(char *, const char
*)' lacks a cast
misc.cpp:361: passing `char' to argument 2 of `strtok(char *, const char
*)' lacks a cast
misc.cpp:362: passing `char' to argument 2 of `strtok(char *, const char
*)' lacks a cast

I am not seeing (blatantly) where the problem lies. Can one of you offer
a tip here?

TIA,

Joe Cipale
--
#----------------------------------------------------------#
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#

Mike Wahler
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Q/Confused



"Joe Cipale" <joec@aracnet.com> wrote in message
news:40928990.193D1D08@aracnet.com...[color=blue]
> I am trying to parse a data entry in a procedure. The procedure will
> parse a data string on either a '/' or a ':'. My proceudre is delcared
> as follows:
> void chr_pad(char dte_str[16], char chr_tok)
>
> The usage is:
> chr_pad(dte_str, '/');
>
> Within the code, I take advantage of the var 'chr_tok' in this manner:
> strcpy(f1, strtok(dte_str, chr_tok));
> strcpy(f2, strtok(NULL, chr_tok));
> strcpy(f3, strtok(NULL, chr_tok));
>
> When I attempt to compile the code, I get the following errors:
> misc.cpp: In function `void chr_pad(char *, char)':
> misc.cpp:360: passing `char' to argument 2 of `strtok(char *, const char
> *)' lacks a cast
> misc.cpp:361: passing `char' to argument 2 of `strtok(char *, const char
> *)' lacks a cast
> misc.cpp:362: passing `char' to argument 2 of `strtok(char *, const char
> *)' lacks a cast
>
> I am not seeing (blatantly) where the problem lies. Can one of you offer
> a tip here?[/color]

Look up the documentation for 'strtok()'. Its second
parameter has type 'const char *', not 'char'.

-Mike


Christopher Benson-Manica
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Q/Confused


Mike Wahler <mkwahler@mkwahler.net> spoke thus:
[color=blue]
> Look up the documentation for 'strtok()'. Its second
> parameter has type 'const char *', not 'char'.[/color]

'Twould be better not to use the dastardly function in the first
place, no?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Closed Thread