cint

cint university / 101 / ced, the cint editor

101-01: printing

This is lesson 101-01 of CU-101.2, checked against cint 0.2.0.

You will draw a picture with characters one line at a time and meet your first error message.

the program

// A house, one line at a time.
"    /\\\n";
"   /  \\\n";
"  /____\\\n";
"  | [] |\n";
"  |____|\n";

Run this program in ced

Run it:

    /\
   /  \
  /____\
  | [] |
  |____|

what happened

The first line is a comment. Everything from // to the end of the line is for people. cint skips it. Comments say what a program is for, or why a line is there.

Each other line is one statement, and each prints one line of the picture. The computer carries them out from top to bottom, so the roof comes out first.

Spaces inside the quotes are printed. The spaces before /\ push the top of the roof to the right, so it sits in the middle.

A backslash is written twice. Inside quotes, a backslash starts an escape code: you met \n, which ends a line. Because of that, a backslash on its own would be read as the start of an escape code. To print one backslash, you write two: \\. So the first statement holds /\\\n: a slash, a backslash written as \\, then \n to end the line.

Four escape codes are all this course needs:

You write cint prints
\n the end of a line
\\ one backslash
\" a double quote, without ending the text
\t a tab, a wide space for lining things up

For example, "She said \"hi\"\n"; prints She said "hi".

change it

  1. Add a chimney to the roof. You will need to change two lines, and add a backslash or two.
  2. Draw the first letter of your name, five lines tall.
  3. Print a line with a quote in it, such as The sign said "open".

when it goes wrong

Leave out the closing quote on the first line of a program:

"Hello, world\n;

Run this program in ced

cint does not run anything. It prints:

error[C1034]: invalid character or string literal
  --> hello.ci:1:1
   |
 1 | "Hello, world\n;
   | ^
   |

Read an error message from the top:

  • error means cint found a problem before running the program, so nothing ran.
  • C1034 is the error's code. Each kind of mistake has its own code, and the list of messages explains each one.
  • The rest of the first line says what kind of problem it is. A string literal is a piece of text in quotes, so this one says the text in quotes is not right.
  • --> hello.ci:1:1 is the source position: hello.ci, the file the program was saved in, then line 1, character 1, counting characters from the left of the line.
  • The picture below it shows that line, with ^ under the place where cint found the problem.

In your browser the same message is laid out differently, with the same code and position.

Here the ^ points at the opening quote, the start of a piece of text that never ends. Put the closing quote back, after \n, and the program runs.

Every lesson from here on ends with one mistake like this, so that you meet each of these messages first in a lesson.

new words

comment, escape code, string literal, error, source position

Next: lesson 101-02, arithmetic.