Originally Posted by
Trying-C
Hi, I want to use C.
but there is no option to choose C or C++???
You just haven't found it yet. What IDE and/or compiler are you using?
Originally Posted by
Trying-C
and I don’t understand what you are talking
about when you say the string in the
printf statement .... I took both “\n” out of the
printf statement and still doesn’t work?!!!
Try to compile this program:
Code:
#include <stdio.h>
int main(void)
{
printf("hello
world\n");
return 0;
}
You should get a compile error. Now try to compile this program:
Code:
#include <stdio.h>
int main(void)
{
printf("hello\nworld\n");
return 0;
}
The program should compile successfully. Then try to compile this program:
Code:
#include <stdio.h>
int main(void)
{
printf("hello\
world\n");
return 0;
}
The program should also compile successfully, but you will find that the output is all on one line.
The idea is that a string literal, i.e., something like "hello\nworld\n" cannot just contain a physical line break (unless you escape that line break so that the two physical lines form a single logical line, which is what the last program demonstrated). This is the issue with your original code: you typed enter when you shouldn't have. It is as simple as that.
In practice, if you do want to break a long string literal across multiple physical lines, you would take advantage of the fact that adjacent string literals ("adjacent" excluding whitespace) are concatenated during compilation, like this:
Code:
#include <stdio.h>
int main(void)
{
printf("hello\n"
"world\n");
return 0;
}