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 CCS Technical Support

Printf is not working when I trying to print variables

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cetinerdemkilinc



Joined: 24 May 2020
Posts: 5

View user's profile Send private message

Printf is not working when I trying to print variables
PostPosted: Sun May 24, 2020 6:43 am     Reply with quote

Hey, I really need help.
I am sending an HTML page via wifi module. And i have to send variables with the HTML string. I am using escape characters for this. If string has under a few hundreds of char, its working fine but my html page has 500+ characters. I'll tell my problem with examples.

It is working great:
Code:
printf("Some strings... And value=%d",15);

And it is working great too:
Code:
printf("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-9\" /></head><title>Termograff WIFI Ayarlarý</title><body bgcolor=\"#272e35\"style=\"font-family:Arial,sans-serif;\"><font color=\"white\"><div><form action=\"/\"method=\"post\"><h1>Wi-Fi Bilgileri</h1>Að adý: <input type=\"text\"name=\"set_ssid\"value=\"\"required><br><br>Þifre:<input type=\"text\"name=\"set_psw\"value=\"\"required><br><br><input type=\"submit\"value=\"Baðlan\"></form></div></font><br></body></html>");

But when i try put variables into this long string:
Code:

char ssid[]="some string here";
char psw[]="and some string here";
printf("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-9\" /></head><title>Termograff WIFI Ayarlarý</title><body bgcolor=\"#272e35\"style=\"font-family:Arial,sans-serif;\"><font color=\"white\"><div><form action=\"/\"method=\"post\"><h1>Wi-Fi Bilgileri</h1>Að adý: <input type=\"text\"name=\"set_ssid\"value=\"%s\"required><br><br>Þifre:<input type=\"text\"name=\"set_psw\"value=\"%s\"required><br><br><input type=\"submit\"value=\"Baðlan\"></form></div></font><br></body></html>",ssid,psw);

This is giving an output like this:
Code:
<html><head><meta http-equiv="Content-Type" content="text/html; ssid"required><br><br>Şifre:<input type="text"name="set_psw"value="psw"required><br><br><input type="submit"value="Bağlan"></form></div></font><br></body></html>

Like you are seeing, it is half.
Yes, it is so interesting and confusing. How can i fix this??
Note: It is not about HTML or wifi module. I tried this with another simple string and result is same, it is sending a half of the string.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Printf is not working when I trying to print variables
PostPosted: Sun May 24, 2020 7:14 am     Reply with quote

cetinerdemkilinc wrote:

I tried this with another simple string and result is same, it is sending a
half of the string.

Post a test program that uses this simple string.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun May 24, 2020 7:23 am     Reply with quote

There is a maximum length limit. This was found/discussed here before.
If I remember correctly it is just over 100 bytes.
You'll just have to split the output into two statements. Not exactly
rocket science....
Remember:
Code:

   printf("This is a message string");
//gives exactly the same output as:
   printf("This is a message");
   printf(" string");

There is also a separate limit on the maximum number of variables that
can be used in a single printf. That is something like 15.
cetinerdemkilinc



Joined: 24 May 2020
Posts: 5

View user's profile Send private message

Re: Printf is not working when I trying to print variables
PostPosted: Sun May 24, 2020 7:29 am     Reply with quote

PCM programmer wrote:
cetinerdemkilinc wrote:

I tried this with another simple string and result is same, it is sending a
half of the string.

Post a test program that uses this simple string.

It is working fine:
Code:
#include <18f46k22.h>
//#device PASS_STRINGS=IN_RAM
#fuses hsh,NOWDT,NOMCLR
#use delay(clock=20M, crystal=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void main()
{   
   printf("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora ");
   while(1);
}

Output:
Code:
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora

But when I tried to print any variable with this:
Code:
#include <18f46k22.h>
//#device PASS_STRINGS=IN_RAM
#fuses hsh,NOWDT,NOMCLR
#use delay(clock=20M, crystal=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void main()
{   
   printf("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora %d",15);
   while(1);
}

The output is:
Code:
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia 15

This is a half of the actual string too.
This string has same character count with my HTML string.


Last edited by cetinerdemkilinc on Sun May 24, 2020 7:46 am; edited 1 time in total
cetinerdemkilinc



Joined: 24 May 2020
Posts: 5

View user's profile Send private message

PostPosted: Sun May 24, 2020 7:39 am     Reply with quote

Ttelmah wrote:
There is a maximum length limit. This was found/discussed here before.
If I remember correctly it is just over 100 bytes.
You'll just have to split the output into two statements. Not exactly
rocket science....
Remember:
Code:

   printf("This is a message string");
//gives exactly the same output as:
   printf("This is a message");
   printf(" string");

There is also a separate limit on the maximum number of variables that
can be used in a single printf. That is something like 15.

Thanks for the reply.
Yes, it is a solution and I can use it. But next steps of this project, i will send strings that contain much more variables. And if i separate string like that, it has so much parts.
If it is impossible to do it in one printf, I have to separate it.
But I did not understand why the limit is valid for only strings containing variable.
cetinerdemkilinc



Joined: 24 May 2020
Posts: 5

View user's profile Send private message

PostPosted: Sun May 24, 2020 7:42 am     Reply with quote

Is there any way to do it in one printf???
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun May 24, 2020 7:44 am     Reply with quote

As soon as you have a variable, the printf, has to 'interpret' the constant
string, instead of just passing it on character by character. It is this process
that has the limitations....
cetinerdemkilinc



Joined: 24 May 2020
Posts: 5

View user's profile Send private message

PostPosted: Sun May 24, 2020 7:57 am     Reply with quote

Ttelmah wrote:
It is this process
that has the limitations....

Well, I think I have to split. But if anyone has a way to do it in a single printf, i will be waiting.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon May 25, 2020 7:56 am     Reply with quote

printf, is designed to send data to things like a screen terminal, or a LCD.
The function targets a maximum line length therefore of 80 characters,
with a bit of a margin.
I'm afraid to send the sort of huge stream you have in mind,
you are either going to have to split it or just use your own replacement
for the supplied printf. I have in the past used part if this small prints
to give support for argument variables:
<https://www.menie.org/georges/embedded/small_printf_source_code.html>
It's not too hard to translate to CCS.
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