Help with sprintf function

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Can anyone tell me why this isn't working and I need to do?

void MyFunc1(void)
{//this is in question
    char xdata myprint[35];
    sprintf(myprint, "Disk space available %u\r\n", disk_size);
    rs232_writeStringX(&myprint);
}


void rs232_writeStringX(char xdata *theString)
{//this is in question
        while ((*theString) != ''){
        rs232_write(*theString);
        theString++;        
    }
}

void rs232_write(Byte theByte)
{//I know this code works.
        TI = FALSE;
        SBUF = theByte;
        while(!TI){}    
        TI = FALSE;                        
}

Re: Help with sprintf function
Quoted text here. Click to load it

Are you sure disk_size will fit in 6 characters? What do you null-terminate
twice? what is xdata? where disk_size comes from? why to use sprintf (such
an expensive function) for such a simple task? If sprintf, why not snprintf?

Quoted text here. Click to load it

This looks OK except for the xdata thing again.

Quoted text here. Click to load it

--
Regards,
Andras Tantos
We've slightly trimmed the long signature. Click to see the full one.
Re: Help with sprintf function
Quoted text here. Click to load it

Lose the "&" - unless I've misplaced my marbles, myprint is already a
pointer.

Steve
http://www.fivetrees.com
http://www.sfdesign.co.uk



Re: Help with sprintf function
snipped-for-privacy@vigoris.net (Sean Whitesell) wrote in

Quoted text here. Click to load it

Either lose the &, or change it to &myprint[0].  Either one should work
interchangably.

--
Richard

Re: Help with sprintf function
Quoted text here. Click to load it

disk_size is undefined.  If it is not unsigned int, you have a parameter
mismatch.
There are no prototypes for sprintf, rs232_writeStringX, or rs232_write
available to the calling routines.  There is a superfluous & in front of
myprint, but this shouldn't cause a problem.
xdata, Byte, TI, FALSE, and SBUF are undefined.  Yes, I know you
probably have most of these defined appropriately, but we have no
confirmation.

Try stepping through your code to see what is happening.  You didn't
mention the symptom you have, so it is harder to guess what the problem
is.

Thad

Site Timeline