Help with sprintf function

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\0", disk_size); rs232_writeStringX(&myprint); }

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

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

Reply to
Sean Whitesell
Loading thread data ...

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?

This looks OK except for the xdata thing again.

--
Regards,
Andras Tantos
Reply to
Andras Tantos

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

Steve

formatting link
formatting link

Reply to
Steve at fivetrees

snipped-for-privacy@vigoris.net (Sean Whitesell) wrote in news: snipped-for-privacy@posting.google.com:

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

--
Richard
Reply to
Richard

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

Reply to
Thad Smith

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.