Jump to content
Sign in to follow this  
Sparky1039

Silly Question For Large Strings In The Ide

Recommended Posts

String question. How do I break up a large string so that it doesn’t run on past the right edge of the IDE code window?

I have a HTML text string that is about ~150 chars long. I can’t seem to figure out how to split it up into multiple lines such that I can neatly view the whole thing in the IDE window. If I do the following the IDE hates it and the compiler serves up an error:

rom char *httpHeader1 = "<html>
<head>
<title>Tower-Cam Test</title>
<body>
<h2>Tower Camera Sensors </h2>
<p>Battery Voltage goes here:</P>
<p> Temperature goes here:</p>
<p>Time goes here:</p>
</body>
</html>";

 

However if the string is all contained on one line extending well past the right edge, the IDE is happy and it compiles ok. Other compilers alow me to do this but not SB-C. So what have I missed? :unsure:

Edited by Sparky1039

Share this post


Link to post
Share on other sites
String question. How do I break up a large string so that it doesn’t run on past the right edge of the IDE code window?

I have a HTML text string that is about ~150 chars long. I can’t seem to figure out how to split it up into multiple lines such that I can neatly view the whole thing in the IDE window. If I do the following the IDE hates it and the compiler serves up an error:

rom char *httpHeader1 = "<html>
<head>
<title>Tower-Cam Test</title>
<body>
<h2>Tower Camera Sensors </h2>
<p>Battery Voltage goes here:</P>
<p> Temperature goes here:</p>
<p>Time goes here:</p>
</body>
</html>";

 

However if the string is all contained on one line extending well past the right edge, the IDE is happy and it compiles ok. Other compilers alow me to do this but not SB-C. So what have I missed? :unsure:

 

You are including new line characters in your string so try using the continuation character after each line (not tested):

rom char *httpHeader1 = "<html>\
<head>\
<title>Tower-Cam Test</title>\
<body>\
<h2>Tower Camera Sensors </h2>\
<p>Battery Voltage goes here:</P>\
<p> Temperature goes here:</p>\
<p>Time goes here:</p>\
</body>\
</html>";

Regards

 

davidb

Share this post


Link to post
Share on other sites

Read [THIS] on strings in C source code in ANSI C90.

 

IMHO you should try the 'ajacent strings combine' method.

rom char *httpHeader1 = 
  "<html>"
  "<head>"
  "<title>Tower-Cam Test</title>"
  "<body>"
  "<h2>Tower Camera Sensors </h2>"
  "<p>Battery Voltage goes here:</P>"
  "<p> Temperature goes here:</p>"
  "<p>Time goes here:</p>"
  "</body>"
  "</html>";
//End of httpHeader1 string

 

If that doesn't work, fall back line continuation characters (DavidB's post above) that I have used in #defines for large inline assembler macros so I *KNOW* they work.

Share this post


Link to post
Share on other sites

David and Ian,

 

Both methods work great. I admit "my original posted code" doesn't work in other compilers either. What I failed to say is most of the other long strings I've used were cut and paste and I didn't study them carefully enough to notice the "continuation characters" ...my bad. :unsure:

It's been a very long time since I've needed massive strings in my code. Now that I'm dabbling with HTTP/HTML in embedded applications I'm finding out how many C skills I've forgotten.

 

Thanks

 

PS. Ian, that's a great online C reference link. Booked marked for sure!

Edited by Sparky1039

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...