Page 1 of 1

Need some help with C

Posted: Thu Apr 05, 2007 7:56 pm
by codemaniac
Hello!

Does anybody know if I can have a code block as a char in C? Maybe not exactly a char, probably tchar or something else, I don't know, because I am just starting out with C :oops:

The code block would be something similar to this:
<html>
<head>
<title>My Cool Website</title>
</head>
<body>
<p>Welcome to my cool website!</p>
</body>
</html>
Thanks!

Posted: Thu Apr 05, 2007 8:00 pm
by KarLKoX

Code: Select all

const char foo[] = "<html><br>\
                       <head><br>\
                       <title>My Cool Website</title><br>\
                       </head><br>\
                       <body><br>\
                       <p>Welcome to my cool website!</p><br>\
                       </body><br>\
                       </html>";

Posted: Thu Apr 05, 2007 8:22 pm
by Tipperton
Don't you need \n instead of just \ or is that a C++ thing?

Like this:

Code: Select all

const char foo[] = "<html><br>\n
                       <head><br>\n
                       <title>My Cool Website</title><br>\n
                       </head><br>\n
                       <body><br>\n
                       <p>Welcome to my cool website!</p><br>\n
                       </body><br>\n
                       </html>";

Posted: Thu Apr 05, 2007 8:29 pm
by codemaniac
Thanks!

Posted: Thu Apr 05, 2007 10:29 pm
by KarLKoX
Tipperton wrote:Don't you need \n instead of just \ or is that a C++ thing?

Like this:

Code: Select all

const char foo[] = "<html><br>\n
                       <head><br>\n
                       <title>My Cool Website</title><br>\n
                       </head><br>\n
                       <body><br>\n
                       <p>Welcome to my cool website!</p><br>\n
                       </body><br>\n
                       </html>";
No, "\n" is only interpreted by functions like print, scanf ... where the '\' char is interpreted by the compiler (the lexer to be more precise).

Posted: Fri Apr 06, 2007 12:04 am
by Tipperton
Hmm.... back when I programed in C durring the DOS days, I recall doing something like this:

Code: Select all

fputs(stdout, "Hello\nWorld!");
and it worked, the output was:
Hello
World!
But if just the \ works, great! That's one less character to type! :mrgreen:

Posted: Fri Apr 06, 2007 12:07 am
by thefool
Tipperton wrote:Hmm.... back when I programed in C durring the DOS days, I recall doing something like this:

Code: Select all

fputs(stdout, "Hello\nWorld!");
and it worked, the output was:
Hello
World!
But if just the \ works, great! That's one less character to type! :mrgreen:
yes as he said, that is for string functions. The \ is for the lexer :)