0
#include <stdio.h>
#include <string.h>

int main() 
{
    char string[] = "firstline of string\n"
              +" second line of string\n"
              +" third line of string\n"
              +"  fourth line of string\n"

int k = strlen(string);
return 0;
}

How can I declare string in multiple lines in C?

This code is giving me errors

  • 2
    Drop the `+` signs; adjacent string literals are concatenated by the compiler at a stage when white space has ceased to be significant. (And, as @MikeCAT noted, add the missing semicolon to terminate the variable definition.) – Jonathan Leffler Nov 23 '16 at 02:48
  • @JonathanLeffler And add `;` after the last line of strings. – MikeCAT Nov 23 '16 at 02:49
  • 1
    Perhaps better dup: [How to split a string literal across multiple lines in C / Objective-C?](http://stackoverflow.com/questions/797318/how-to-split-a-string-literal-across-multiple-lines-in-c-objective-c/11218488#11218488) – kaylum Nov 23 '16 at 02:53

0 Answers0