0

I am using Visual Code Studio as my IDE, and wanted to write a simple snippet for printing:

printf("%d", );

the snippet:

 "Print": {
    "prefix": "printf",
    "body": [
        "printf("%d",$1);",
        "$2"
    ],
    "description": "print"
}

It is a JSON file, however it gives me an error with %d and doesnt treat %d as a string, I suppose. The error being: Expected commajson(514)

2
  • 1
    You need \" instead of " inside of the snippet. Take a look at this.
    – CherryDT
    Commented Aug 2, 2020 at 21:38
  • The " of printf messes up your json
    – Marged
    Commented Aug 2, 2020 at 21:39

1 Answer 1

2

You need to escape double-quotes that appear in strings with a backslash, otherwise it looks like you're ending and restarting the string:

 "Print": {
    "prefix": "printf",
    "body": [
        "printf(\"%d\",$1);",
        "$2"
    ],
    "description": "print"
}
1
  • thanks! this did the work Commented Aug 2, 2020 at 21:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.