Skip to content

Commit

Permalink
Merge pull request #2 from fork-for-humanity/main
Browse files Browse the repository at this point in the history
C documentation begin
  • Loading branch information
osmancoskun committed May 20, 2024
2 parents 56dc2ab + ebfe66e commit dddaae4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
81 changes: 81 additions & 0 deletions src/routes/wiki/development/c/c-101.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# C gtk tutorial

C is one of the most fundamental programming languages.
Being a compiled language, it requires a compiler such as gcc or clang.

## Installing compiler

You can use `apt install gcc` command to install gcc.
```shell
$ apt install gcc
```

Or you can prefer clang:
You can use `apt install clang` command to install clang.
```shell
$ apt install clang
```

## Standard C Library (libc)

Every GNU/Linux distribution comes with a libc.
Libc is the most basic library on the system, and all programs, regardless of what they are written in, eventually call libc functions somewhere.
Writing programs without using libc functions is very difficult.

Pardus GNU/Linux prefer glibc as libc library.

You must install **libc6-dev** package for libc development files.

```shell
$ apt install libc6-dev
```

## Write Simple C application

Lets write simple hello world program:

```c
#include <stdio.h>

int main(int argc, char** argv){
printf("Hello World\n");
return 0;
}
```
### Explaining hello world
```c
#include <stdio.h>
```
* #include <stdio.h>: This line is a preprocessor directive that tells the compiler to include the contents of the stdio.h header file.
This header file contains declarations for standard input/output functions like printf and scanf, which are used in the program.

```c
int main(int argc, char** argv) {
```
* int main(int argc, char** argv) {: This line defines the main function of the program.
In C, every program must have a main function, which serves as the entry point of the program. It takes two arguments: argc, an integer representing the number of command-line arguments passed to the program, and argv, an array of strings containing the actual command-line arguments.
```c
printf("Hello World\n");
```

* printf("Hello World\n");: This line uses the printf function to print the string "Hello World" to the standard output (usually the console).
The \n represents a newline character, which moves the cursor to the next line after printing "Hello World".

```c
}
```
* }: This closing curly brace marks the end of the main function block.
All the code within the main function is enclosed between { and }.

### Compile code

Compile code like this and run:

```shell
$ gcc main.c -o main
$ ./main
>>> Hello World
```
2 changes: 2 additions & 0 deletions src/routes/wiki/development/c/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# C documentations
This section provide C related documentations.
File renamed without changes.

0 comments on commit dddaae4

Please sign in to comment.