You are looking at lesson 9. Your place is still lesson 6, task 1: Arrays.
A string is a char array with '\0' at the end. strlen and sizeof, %s, literals and const char *, Lithuanian letters at 2 bytes each.
Until now, text lived only in printf's quotes. In this topic you keep text in variables, and at the end you write your own input.h.
C has no separate string type. A string is a char array whose text ends with a special character '\0' (a byte equal to 0). That is how every function knows where the text ends.
char name[8] = "Ona";
"Ona" in quotes is a string literal: 3 letters and a '\0' at the end, 4 bytes in all.'\0' takes room too.| what it counts | name |
|
|---|---|---|
strlen(name) |
the bytes up to '\0' |
3 |
sizeof name |
the size of the whole array | 8 |
strlen (from <string.h>) walks the text up to '\0' every time, so it's worth keeping its result in a variable rather than calling it in a loop condition on every pass.
CLion saves files in UTF-8: a Latin letter is 1 byte, and ą, ž, ė and the other Lithuanian ones are 2 each. A C string counts bytes, not letters, so strlen("ąžuolas") ("oak") is 9 although it has 7 letters. That matters when you count room in an array: the name "Žydrūnė" needs 10 bytes plus one more for '\0'.
printf("Hello, %s!\n", name);
%s prints the bytes from the start of the array up to '\0'. If there is no '\0', printf carries on through memory printing garbage – or the program crashes.
const char *city = "Kaunas";
The literal "Kaunas" sits in memory that can't be changed. A pointer to it is written with const: then the compiler won't let you write through it. If the text needs changing, copy it into an array of your own – char city[20].
Each one ticks itself when you do it.
All six done. You know your way around.
It is laid out like CLion: the same panels in the same places. This tour shows each one, and you can reopen it any time with Tour.
Switches the left panel: Lesson plan, Project files, Changes. Click the active icon again to hide the panel.
In CLion: the tool window bar runs down the left edge, too.
This part is not on this task: it appears when a task needs it.
Every task in this lesson. Now marks your place. Clicking a task only lets you look; it never moves your place. Project files and Changes open here too.
In CLion: this spot holds the Project view (the file tree).
This part is not on this task: it appears when a task needs it.
Opens the file for your task by itself. A tab appears for each file the step opens. The breadcrumbs above the code show the folder.
In CLion: the same editor tabs and breadcrumbs.
This part is not on this task: it appears when a task needs it.
Diff shows what changed, like git diff: red is the old code, green the new.
In CLion: the diff view in the Commit window looks the same.
This part is not on this task: it appears when a task needs it.
Terminal for build commands, Database to see your tables. They open by themselves when a task needs them. Drag the top edge to resize.
In CLion: Terminal, and the Database tool window.
This part is not on this task: it appears when a task needs it.
What to do now, right above the code, so you never miss it. Numbered notes in the code explain the important lines. Details shows what you should see and a hint.
In CLion: no equivalent: this is your lecturer's guide.
This part is not on this task: it appears when a task needs it.
Done is the only button that moves you forward. Look back lets you review without losing your place.
This part is not on this task: it appears when a task needs it.
Guided, Focus code or Floating. You can drag the panel edges too. Your layout is remembered for next time.
In CLion: you can also rearrange and hide tool windows.
This part is not on this task: it appears when a task needs it.
Six small missions. Each one ticks itself when you do it, so you know you have found everything.