CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

printf broken?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
poul holmoe thomsen
Guest







printf broken?
PostPosted: Fri Aug 23, 2002 12:41 pm     Reply with quote

After updating to the latets PCWH today, i found that the
printf() is not working correctly:

int f
printf(tostring,"\f\%02u",f);

Before I got a leading zero.
After updating the leading zero has disappered
and some times the result is garbled.

I use this routine to print the time and to make telegrams, so you can imagine that i am in trouble now.

regards

Poul
___________________________
This message was ported from CCS's old forum
Original Post ID: 6551
Hans Wedemeyer
Guest







Re: printf broken?
PostPosted: Fri Aug 23, 2002 4:16 pm     Reply with quote

:=int f
:=printf(tostring,"\f\%02u",f);

What is \f ? I should think the compiler will compain about that.

As you have PCWH why not use sprintf(buf,"\%02u",f); and avoid the old printf() code. That way tostring is no longer needed and sprintf() will use the buffer directly.

I forget is int signed by default ? if so then you need \%d not \%u !
___________________________
This message was ported from CCS's old forum
Original Post ID: 6563
mouse_clicker
Guest







related questions and stuff -->Re: printf broken?
PostPosted: Sat Aug 24, 2002 10:53 am     Reply with quote

:=:=int f
:=:=printf(tostring,"\f\%02u",f);
:=
:=What is \f ? I should think the compiler will compain about that.
:=
:=As you have PCWH why not use sprintf(buf,"\%02u",f); and avoid the old printf() code. That way tostring is no longer needed and sprintf() will use the buffer directly.
:=
:=I forget is int signed by default ? if so then you need \%d not \%u !

I'm not familiar with "tostring" or "buf" as it's used above. Care to shine a light on these types of pieces? What's it do, how's it used, etc.? I've got a few books on C, and none of them seem to cover the printf() function completely. Also, BTW, (one of my books says) \f is supposed to be "formfeed", but I've not been able to get it to work, or Tera Term (set to emulate VT-100 terminal) doesn't seem to respond to it as expected. I would expect it to scroll down a bunch, shifting any text on the terminal upward and off the screen.

Regards,

Greg
___________________________
This message was ported from CCS's old forum
Original Post ID: 6571
Tomi
Guest







Re: related questions and stuff -->Re: printf broken?
PostPosted: Sat Aug 24, 2002 11:16 am     Reply with quote

:=I'm not familiar with "tostring" or "buf" as it's used above. Care to shine a light on these types of pieces? What's it do, how's it used, etc.?

The "printf(tostring,"\%02u",f);" is the old style method to print a formatted string into a char array instead of the serial port. "tostring" is a function declared as "void tostring(char nextchar)". It saves the input char into an array, writes out onto LCD, etc. In this aspect the printf(\%02u",f) call is equivalent with printf(putch,\%02u",f).

The other form "sprintf(buf,"\%02u",f)" suggested by Hans is a "new" feature in Version3 but a standard function in K&R C.

I think \f is not supported in V3. Intead of this you can use one of the new features of V3:
printf(tostring,"\x0C\%02u",f); // enter 0x0C as the 1st char
(You can enter the direct HEX code of any character using "\xXX" form, e.g. "ABCD\x0A\x0B\x0C\x0DE" is in HEX: 41 42 43 44 0A 0B 0C 0D 45)
___________________________
This message was ported from CCS's old forum
Original Post ID: 6572
poul holmoe thomsen
Guest







Re: printf broken?
PostPosted: Sun Aug 25, 2002 7:38 am     Reply with quote

:=I forget is int signed by default ? if so then you need \%d not \%u !

The int is unsigned as default.

and the \f should make the tostring start a new line. Without \ the call to tostring will append the line. (So have it been working for as long as I had worked on my project)

Then suddenly when I upgrade to the latest pcwh the function is broken regarding the leading zero.

Anyway, tomorrow monday when I am back at work, I will try out the sprinf. And if it works I will just have to rewrite my code accordingly.


Thanks for your answer.



___________________________
This message was ported from CCS's old forum
Original Post ID: 6586
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: printf broken?
PostPosted: Sun Aug 25, 2002 4:26 pm     Reply with quote

:=Then suddenly when I upgrade to the latest pcwh the function is broken regarding the leading zero.
:=
---------------------------------------------------
With CCS, you need to keep an archive of each version,
so that you can revert to an older version if the latest
one has a bug. For example, you can have a folder called
C:\Downloads\CCS\, and it will contain all the versions
that you've downloaded. Just rename the default filename
so that it contains the version number. Your folder will
look like this:

pcwh3107.exe
pcwh3106.exe
pcwh3105.exe
pcwh3104.exe
etc.
etc.

I have been doing this for several years.
___________________________
This message was ported from CCS's old forum
Original Post ID: 6593
Poul Holmoe Thomsen
Guest







Re: printf broken?
PostPosted: Mon Aug 26, 2002 2:22 am     Reply with quote

:=I have been doing this for several years.

You are right. I have now reinstalled the previous version, and
now both printf and sprintf are working ok.

I have send a new message to see if other programmers
uses the same formtastring as I do.


8 hours work in the bin.


thanks for your advise

best regards
poul
___________________________
This message was ported from CCS's old forum
Original Post ID: 6609
Poul Holmoe Thomsen
Guest







Re: printf broken?
PostPosted: Mon Aug 26, 2002 2:22 am     Reply with quote

:=I have been doing this for several years.

You are right. I have now reinstalled the previous version, and
now both printf and sprintf are working ok.

I have send a new message to see if other programmers
uses the same formtastring as I do.


8 hours work in the bin.


thanks for your advise

best regards
poul
___________________________
This message was ported from CCS's old forum
Original Post ID: 6610
jvbiljon
Guest







PRINTF to String PROBLEM
PostPosted: Tue Jan 22, 2008 2:08 am     Reply with quote

I am currently trying the old method of printing to a string as I do not yet have the compiler supporting sprintf function.

I do not understand why I keep seeing garbage printouts...

Example:

<BT> 123</BT> ÒACK Sent
<Tag>
<Id> 1234</Id>
</Tag>

The 1st line is my Test line - and I see the funny charachter prints... The ACK Sent line should be printed in a new line...

Why does the printf(tostring,"\f <BT>%d</BT>\n\r",n); command do that?

The tostring function looks like this...
void tostring(char c)
{
if(c == '\f')
stringptr = 0;
else
string[stringptr] = 0;

string[stringptr++] = c;
}

Regards,
Justus van Biljon
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jan 23, 2008 10:49 am     Reply with quote

Quote:
Code:
void tostring(char c)
{
if(c == '\f')
stringptr = 0;
else
string[stringptr] = 0;

string[stringptr++] = c;
}


Try:

Code:
void tostring(char c)
{
   if(c == '\f')
      stringptr = 0;
   else {
     string[stringptr+1] = 0;
     string[stringptr++] = c;
  }
}


That way you will always have a terminating 0, and your string will print Ok.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group