Need Help with the sprintf command 
Author Message
 Need Help with the sprintf command

[this came in a bit weirdly formatted; with any luck, I did no damage in
 fixing it. -mod]

I am in the process of moving code from an old DEC Ultrix server to a
Linux server.  In the process many lines of code are being re-compiled.
One specific instance is giving me a problem.  Hopefully someone out
there can assist.

I have the following definition:

db_name ( systable, tabl_name )
    char *systable;
    char *tabl_name;
{
    int num_try;

snip

    sprintf( sys_filen, "%s%s", systable,"systables\0" );

When I compile this on Linux, I get the following:

info_sys.c: In function `db_name':
info_sys.c:46: warning: passing arg 1 of `sprintf' from incompatible
pointer type

What did I do wrong?  This compiles without complaints on
a DEC Ultrix server.

Thanks in advance for your answers!

--

http://www.*-*-*.com/
------------------------------------------------------------------
Sr. Database, Internet and Unix Systems Consultant

Pennsylvania Parenthood Initiative - It takes two people to become
parents, the children need both of them!
http://www.*-*-*.com/
Parents without Partners - Past President
Co-Founder of The Purple Heart Foundation
--



Wed, 19 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command

Quote:
>     sprintf( sys_filen, "%s%s", systable,"systables\0" );

> info_sys.c:46: warning: passing arg 1 of `sprintf' from incompatible
> pointer type

You must show us the definition of sys_filen in order for us to
be able to help you.

[snippage]
--
"To the engineer, the world is a toy box full of sub-optimized and
 feature-poor toys."
--Scott Adams
--



Fri, 21 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command
Albert E. Whale a crit dans le message ...

Quote:
>[this came in a bit weirdly formatted; with any luck, I did no damage in
> fixing it. -mod]

>I am in the process of moving code from an old DEC Ultrix server to a
>Linux server.  In the process many lines of code are being re-compiled.
>One specific instance is giving me a problem.  Hopefully someone out
>there can assist.

>I have the following definition:

>db_name ( systable, tabl_name )
>    char *systable;
>    char *tabl_name;

Do you really have to use this (very)ol'definition style ? C has been ISO
since 1990.
Ah ok, I have read your post again, and it seems to come from an old code. I
suggest you change the functions definitions to ISO style, and give correct
prototypes to your public functions.

Quote:
>{
>    int num_try;

>snip

>    sprintf( sys_filen, "%s%s", systable,"systables\0" );

Show us the definition of sys_filen. I suspect it is not a valid string.

Quote:
>When I compile this on Linux, I get the following:

>info_sys.c: In function `db_name':
>info_sys.c:46: warning: passing arg 1 of `sprintf' from incompatible
>pointer type

>What did I do wrong?  This compiles without complaints on
>a DEC Ultrix server.

Old code, old machine, old compiler ?

--
-hs-
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC

--



Fri, 21 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command
Hi Albert,



Quote:
> [this came in a bit weirdly formatted; with any luck, I did no damage in
>  fixing it. -mod]

[ I hope I didn't{*filter*}it back up, now :-) ]

[sniplets]

Quote:
> I have the following definition:

> db_name ( systable, tabl_name )
>     char *systable;
>     char *tabl_name;
> {
>     int num_try;

> snip

>     sprintf( sys_filen, "%s%s", systable,"systables\0" );

I hope, sys_filen is of type char *. If not, your Linux compiler is right
after all :-)

[snipped the rest]

--



Fri, 21 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command

Quote:

> I have the following definition:

> db_name ( systable, tabl_name )
>     char *systable;
>     char *tabl_name;
> {
>     int num_try;

> snip

>     sprintf( sys_filen, "%s%s", systable,"systables\0" );

> When I compile this on Linux, I get the following:

> info_sys.c: In function `db_name':
> info_sys.c:46: warning: passing arg 1 of `sprintf' from incompatible
> pointer type

> What did I do wrong?  This compiles without complaints on
> a DEC Ultrix server.

arg 1 is sys_filen, for which there is no definition visible.  This
means that it impossible for anyone to suggest how you have misdefined
it.  It should be either the name of or a pointer to a sufficiently
large array of char.

--

What one knows is, in youth, of little moment; they know enough who
know how to learn. - Henry Adams

A thick skin is a gift from God. - Konrad Adenauer
__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com
--



Fri, 21 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command
On Sat, 01 Jan 2000 19:26:38 GMT, "Albert E. Whale"

Quote:
> [this came in a bit weirdly formatted; with any luck, I did no damage in
>  fixing it. -mod]

> I am in the process of moving code from an old DEC Ultrix server to a
> Linux server.  In the process many lines of code are being re-compiled.
> One specific instance is giving me a problem.  Hopefully someone out
> there can assist.

> I have the following definition:

> db_name ( systable, tabl_name )
>     char *systable;
>     char *tabl_name;

Ugh, if you're rewriting the code you COULD change it to use ANSI/ISO
function definitions.  They were only added to the language over 10
years ago.

You know:

int db_name(char *systable, char *tabl_name)
{

Quote:
> {
>     int num_try;

> snip

>     sprintf( sys_filen, "%s%s", systable,"systables\0" );

Writing a string literal and explicitly adding \0 inside the quotation
marks has /never/ been necessary.  This makes me wonder about the
capabilities of whoever originally wrote this code.

Quote:
> When I compile this on Linux, I get the following:

> info_sys.c: In function `db_name':
> info_sys.c:46: warning: passing arg 1 of `sprintf' from incompatible
> pointer type

> What did I do wrong?  This compiles without complaints on
> a DEC Ultrix server.

> Thanks in advance for your answers!

The problem is that you did not give anyone enough information to
answer your question.  The compiler is complaining about the first
argument in the call to sprintf(), which is sys_filen.  You did not
include the definition of sys_filen.  Is it defined as an array of
chars, or a pointer to char which has been assigned the address of an
array of chars?

Post again with the definition of sys_filen.  The name sounds like it
might be a FILE pointer, although it is risky to make such guesses, so
perhaps somebody mistyped "fprintf" as "sprintf"?

Jack Klein
--
Home: http://jackklein.home.att.net
--



Fri, 21 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command

Quote:
> db_name ( systable, tabl_name )
>     char *systable;
>     char *tabl_name;
> {
>     int num_try;

> snip

>     sprintf( sys_filen, "%s%s", systable,"systables\0" );

> When I compile this on Linux, I get the following:

> info_sys.c: In function `db_name':
> info_sys.c:46: warning: passing arg 1 of `sprintf' from incompatible
> pointer type

What's sys_filen? Where and how is it defined? It should be a pointer
to char and db_name should know about it somehow. It is not obvious
from the fragment you provided what is happening, but assuming the
sprintf statement is on line 46 the compiler does not like something
about sys_filen. And certainly you included stdio.h, didn't you?

--

"... We work by wit, and not by witchcraft;
 And wit depends on dilatory time." - W. Shakespeare.
--



Fri, 21 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command

Quote:

> Post again with the definition of sys_filen.  The name sounds like it
> might be a FILE pointer, although it is risky to make such guesses, so
> perhaps somebody mistyped "fprintf" as "sprintf"?

Interesting idea - this possibility didn't occur to me because
I interpreted sys_filen as "filename", and decided that sprintf()
was used to create a file name. Let's wait for a clarification.

--

"... We work by wit, and not by witchcraft;
 And wit depends on dilatory time." - W. Shakespeare.
--



Sat, 22 Jun 2002 03:00:00 GMT  
 Need Help with the sprintf command


Quote:
>Ugh, if you're rewriting the code you COULD change it to use ANSI/ISO
>function definitions.  They were only added to the language over 10
>years ago.

True, but it needs to be done carefully because you cannot always grab
what you see and relocate it.

Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
--



Sat, 22 Jun 2002 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. sprintf command

2. need help with command line arguments

3. system() command help needed

4. Disk commands - help needed to control

5. Need Help: ADODB::Command

6. Need help with Execute method of Command object

7. need help on CEdit command

8. HELP NEEDED :Command line error D2022

9. Need Help On CEdit command

10. Clist Dir Command help needed please`

11. HELP NEEDED Command line error D2022

12. Need sprintf algorithm.

 

 
Powered by phpBB® Forum Software