Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomiis4/CLang
My CLang projects with cheatsheet
https://github.com/tomiis4/CLang
c c-cheatsheet cheatsheet
Last synced: 2 months ago
JSON representation
My CLang projects with cheatsheet
- Host: GitHub
- URL: https://github.com/tomiis4/CLang
- Owner: tomiis4
- Created: 2022-10-15T15:48:53.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-02T16:41:26.000Z (about 1 year ago)
- Last Synced: 2023-10-02T22:38:16.074Z (about 1 year ago)
- Topics: c, c-cheatsheet, cheatsheet
- Language: C
- Homepage:
- Size: 212 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# C Cheatsheet
* [File](#file)
* [Hello world](#hello-world)
* [Importing libraries](#importing-libraries)
* [Variables](#variables)
* [struct](#struct)
* [Functions](#functions)* [Logic statements](#logic-statements)
* [if/else](#ifelse)
* [switch/case](#switchcase)
* [Loops](#loops)
* [for-i](#for-i)
* [while](#while)* [Converting](#converting)
* [Build-in iunctions](#build-in-functions)
* [printf](#printf)
* [scanf](#scanf)
* [memory](#memory)* [Pointers](#pointers)
* [Libraries](#libraries)
* [time.h](#time.h)
* [Projects](#projects)## File
### Run file
```sh
gcc .c -o .exe./.exe
```## Hello world
```c
#includeint main() {
printf("Hello, world\n");return 0;
}
```## Importing libraries
```c
#include
```## Variables
```c
// declare variable
= ;// declare array
[] = {, };// string
char [] = "";
char [] = "";/*
Types:
unsigned int, short, long = %u = positive number
signed int, short, long = %d = negative numbersbool = %d = true/false
char = %c = one character (in single quiote)
int = %d = numbers
short = %hd = numbers (-32_768 to 32_767)
long = %ld = numbers (-9223372036854775808 to 9223372036854775807)float = %f = floating numbers (6 decimals)
double = %lf = floating numbers (15 decimals)
long double = %Lf = floating numbers (19 decimals)void = N/A = only for function return as empty
*/
```### structs
```c
// create struct
struct {
;
;
}// initialize empty struct variable
struct ;// initialize filled struct variable
struct = {, };
```## Functions
```c
name() {
//...
}// return
name() { return x }// parameters
name( param1) { }
```## Logic statements
### If/else
```c
if (condition) {
//...
} else if (condition2) {
//...
} else {
//...
}
```### Switch/case
```c
switch (statement) {
case x:
//...
break;
case y:
//...
break;
default:
//...
}
```## Loops
### For-I
```c
for (int i=0; i < 10; i++) {
//...
}
```### While
```c
while (condition) {
//...
}
```## Converting
```c
// str -> int
#includeint number = atoi();
// int -> str
#includechar str[20];
sprintf(str, "%d", );// int -> float
float decimal = (float) ;// float -> int
int number = (int) ;
```## Build-In Functions
### printf
```c
// print formatted output// without variable
printf("Hello, world");// with variable
printf("Hello, ", );
```### scanf
```c
// get user inputscanf(, );
```### memory
```c
// todo
```## Pointers
```c
// create new pointer variable with name pointer
*pointer;// change pointer address
;
pointer =// change data from address/pointer
*pointer =// read data from address/pointer
*pointer// get address from variable
&variable
```## Libraries
### time.h
```c
// get start time
clock_t startTime = clock();// create delay
void delay(int ms) {
clock_t startTime = clock();while (clock() < startTime + msDelay);;
}
```## Projects
- Calculator
- Sorting algorithm
- Snake