Operating System - HP-UX
1753554 Members
4302 Online
108795 Solutions
New Discussion юеВ

warning #2226-D: invalid format string conversion

 
SOLVED
Go to solution
Curtis Deese
Frequent Advisor

warning #2226-D: invalid format string conversion

I get the following warning when trying to compile some C code:

cc -D_USE_BIG_FDS -Ae -DHPUX -DORAIA64 -DHPUX_IA64 +DD64 -DSS_64B -IT_S
ERVER -DHPPA64 -DSLS8NATIVE -DSLU8NATIVE +DD64 -DSS_64BIT_SERVER /u01/app/oracle
/product/11.2.0/clnt/precomp/public/ -c CacheUtils.c
"CacheUtils.c", line 30: warning #2226-D: invalid format string conversion
g_cache_db_criterias[i].ac_where_clause_02,g_cache_db_cr
iterias[i].ac_from_clause);

Here are the lines of code that are causing the problem:

printf("%-5d%-20s%\n-20s%-20s\n",g_cache_db_criterias[i]
.i_criteria_id,g_cache_db_criterias[i].ac_where_clause_01,\
g_cache_db_criterias[i].ac_where_clause_02,g_cac
he_db_criterias[i].ac_from_clause);

Why am I getting this warning and how do I resolve it?

Thanks,

Curtis
3 REPLIES 3
Steven Schweda
Honored Contributor
Solution

Re: warning #2226-D: invalid format string conversion

> [...] "%-5d%-20s%\n-20s%-20s\n" [...]

In there, I see: "%-5d", "%-20s", "%\n-20s",
and "%-20s\n". That third one troubles me.
"HP C V7.3-009 on OpenVMS Alpha V8.3" doesn't
seem to like it much, either:

alp $ type fmt.c
#include

int main( void)
{
char *cs1 = "cs1";
char *cs2 = "cs2";
char *cs3 = "cs3";
int i1 = 1;

printf( "%-5d%-20s%\n-20s%-20s\n",
i1, cs1, cs2, cs3);
}
alp $ cc fmt.c

printf( "%-5d%-20s%\n-20s%-20s\n",
............^
%CC-W-BADCONVSPEC, In this statement, this argument to printf contains a bad conversion specification "%
" that will cause unpredictable behavior.
at line number 10 in file ALP$DKA0:[SMS.ITRC]fmt.c;1

Note that it seems to be complaining about
the "%\n".
Dennis Handly
Acclaimed Contributor

Re: warning #2226-D: invalid format string conversion

>printf("%-5d%-20s%\n-20s%-20s\n"

If it isn't obvious, you probably want:
printf("%-5d%-20s\n%-20s%-20s\n"
Curtis Deese
Frequent Advisor

Re: warning #2226-D: invalid format string conversion


printf("%-5d%-20s\n%-20s%-20s\n"

resolved the problem.

Thanks,

Curtis