Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Algorithm.

READTask 14 of 21 · step 6: Common mistakesCommon mistakes
Common mistakes in practice/01/

Six mistakes almost everyone makes in the first week. When something doesn't work, check this list first.

Details & hint

Almost everyone makes these mistakes in the first week. When the program does not build, or prints something you didn't expect, check this list first.

Common mistakes
  • Missing ;. error: expected ';' before ...: the semicolon is missing where the ^ points, usually at the end of a line.
  • Main instead of main. C tells capital and small letters apart. The code compiles, but the linker cannot find where the program starts: undefined reference to 'WinMain' (Windows) or undefined reference to 'main' (Linux, GitHub CI).
  • Forgot #include <stdio.h>. implicit declaration of function 'printf', and on the next line the compiler itself writes: include '<stdio.h>'.
  • \n in a path. "C:\new" gives no error: \n becomes a new line. In a path always write \\.
  • A single %. printf("100%") does not work, you need 100%%.
  • The new program is not in the list next to ▶. You created practice/NN/CMakeLists.txt, but CLion hasn't seen it yet: File → Reload CMake Project.

Extra: Lithuanian letters in the Run window

Optional. The course programs print English only, without Lithuanian letters; only topic 9 and practice test 2 use them on purpose, and show this setting again there. If your own program prints, say, Pažymys and the Run window shows Pažymys, the program writes UTF-8 but the window reads another encoding: Settings → Editor → General → Console → Default Encoding: UTF-8.

practice 01 main.c Code Diff
UNCHANGED This step does not change this file.
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
printf("\n");
printf("Algorithm: the average of grades\n");
printf("1. Add up all the grades.\n");
printf("2. Count how many grades there are.\n");
printf("3. Divide the sum by the count.\n");
printf("4. Print the answer.\n");
printf("\n");
printf("Grade\tMeaning\n");
printf("10\t\"excellent\"\n");
printf("5\t\"satisfactory\"\n");
printf("File: C:\\course\\practice\\01\\main.c\n");
printf("Done: 100%%\n");
return 0;
}