Q/Confused

J

Joe Cipale

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 #
#----------------------------------------------------------#
 
M

Mike Wahler

Joe Cipale said:
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?

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

-Mike
 
C

Christopher Benson-Manica

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top