My program just doesn't work. I get this error.

population/ $ make test
test.c:6:9: error: missing terminating '"' character [-Werror,-Winvalid-pp-token]
printf(R"EOF(
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 errors generated.
#include <stdio.h>
#include <cs50.h>

int main(void)
{
printf(R"EOF(
   _____       _               _ _   _           _   _              _____           _
  / ____|     | |             (_) | | |         | | | |            / ____|         (_)
 | (___  _   _| |__  _ __ ___  _| |_| |_ ___  __| | | |__  _   _  | |    _   _ _ __ ___  __
  \___ \| | | | '_ \| '_ ` _ \| | __| __/ _ \/ _` | | '_ \| | | | | |   | | | | '__| \ \/ /
  ____) | |_| | |_) | | | | | | | |_| ||  __/ (_| | | |_) | |_| | | |___| |_| | |  | |>  <
 |_____/ \__,_|_.__/|_| |_| |_|_|\__|\__\___|\__,_| |_.__/ \__, |  \_____\__, |_|  |_/_/\_\
                                                            __/ |         __/ |
                                                           |___/         |___/
)EOF");
}
2

There are 2 best solutions below

5
Vlad from Moscow On BEST ANSWER

This construction

R"EOF(
   _____       _               _ _   _           _   _              _____           _
  / ____|     | |             (_) | | |         | | | |            / ____|         (_)
 | (___  _   _| |__  _ __ ___  _| |_| |_ ___  __| | | |__  _   _  | |    _   _ _ __ ___  __
  \___ \| | | | '_ \| '_ ` _ \| | __| __/ _ \/ _` | | '_ \| | | | | |   | | | | '__| \ \/ /
  ____) | |_| | |_) | | | | | | | |_| ||  __/ (_| | | |_) | |_| | | |___| |_| | |  | |>  <
 |_____/ \__,_|_.__/|_| |_| |_|_|\__|\__\___|\__,_| |_.__/ \__, |  \_____\__, |_|  |_/_/\_\
                                                            __/ |         __/ |
                                                           |___/         |___/
)EOF" 

represents a raw string literal the notion of which is defined in C++.

In C such a construction is absent.

Instead you need to write adjacent string literals with new line characters '\n' something like the following

  " _____       _               _ _   _           _   _              _____           _\n"
  "/ ____|     | |             (_) | | |         | | | |            / ____|         (_)\n"
 "| (___  _   _| |__  _ __ ___  _| |_| |_ ___  __| | | |__  _   _  | |    _   _ _ __ ___  __\n"
  "\___ \| | | | '_ \| '_ ` _ \| | __| __/ _ \/ _` | | '_ \| | | | | |   | | | | '__| \ \/ /\n"
  "____) | |_| | |_) | | | | | | | |_| ||  __/ (_| | | |_) | |_| | | |___| |_| | |  | |>  <\n"
 "|_____/ \\__,_|_.__/|_| |_| |_|_|\\__|\\__\\___|\\__,_| |_.__/ \\__, |  \\_____\\__, |_|  |_/_/\\_\\\n"

and so on.

They will be concatenated by the compiler as one string literal.

Pay attention to that in C++ you may insert a character like \ in a raw string literal and it will be outputted as is but in C you need to use escaped sequence in a string literal like \\ to output the symbol '\'.

Otherwise compile your program as a C++ program.:)

2
Chris On

String literals in C cannot span multiple lines unless the newlines are escaped.

However, adjacent string literals are automatically concatenated, so the following works:

const char *foo = "foo\n" "bar\n" "baz";

And since the whitespace between the string literals is insignificant, we can write the following:

const char *foo = 
    "foo\n"
    "bar\n"
    "baz";

Vs.

const char *foo = "foo
bar
baz";

As mentioned in comments, you can escape the newlines with backslashes. However, in this case you must still remember to insert the newline characters manually.

const char *foo = "foo\n\
bar\n\
baz";

I am not a fan of this as it prevents indentation of code, which is important for being able to follow control flow and scope.