Forum Discussion
Altera_Forum
Honored Contributor
20 years ago --- Quote Start --- originally posted by fmcmurra+mar 28 2006, 10:41 pm--><div class='quotetop'>quote (fmcmurra @ mar 28 2006, 10:41 pm)</div>
--- quote start ---
<!--quotebegin-shakthi@Mar 28 2006, 03:12 AM hi,
i am working on a custom board with nios2. i am facing a weird problem with printf.
when i do any printf i am getting an inversed output.
i.e. if i do printf("hello world"); i get ehll oowlrd. take 2 chars from h and reverse. u get the o/p i am getting.
all this is happening in vsprintf which is called by printf for formatting.
below i will give the code snippet where things are going wrong.
int vsprintf(char *buf, const char *fmt, va_list args)
{
...................
char * str;
...................
for (temp=str=buf ; *fmt ; ++fmt) {
if (*fmt != '%') {
*str++ = *fmt;
continue;
}
.....................
case 's':
s = va_arg(args, char *);
if (!s)
s = "<null>";
len = strnlen(s, precision);
if (!(flags & left))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len ; ++i)
*str++ = *s++;
while (len < field_width--)
*str++ = ' ';
continue;
....................
}
for (i = 0; i < len ; ++i)
*str++ = *s++;
this is where every thing goes wrong.
suppose s="hello from niosii!" it coppies correctly to str but it appears as mentioned above in buf i.e "ehll oofmon oiisi.
clue:
for loop which is suppose to incerement from 0 to len, actually decrements from len to 0. i beleive it is compiler optimization.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=13861)
--- quote end ---
--- Quote End --- Looks like it's byte swapped to me... <div align='right'><{post_snapback}> (index.php?act=findpost&pid=13873)</div> [/b] --- Quote End --- <div class='quotetop'>QUOTE </div> --- Quote Start --- Yappppp its a byte swap[/b] --- Quote End ---