GodlyPacketz

[C/Learn] Beginners Tutorial

Oct 19th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.17 KB | Source Code | 0 0
  1. VIM:
  2.   - CMD to start vim [ vim <filename> ]
  3.   - vim has different modes
  4.     * Insert Mode
  5.  
  6.   - To enter Insert Mode press I
  7.   - To exit Insert Mode press Esc
  8.   - The left of green block is where cursor is
  9.   - To exit do Esc and :q
  10.   - To save do Esc and :w
  11.     * Put :qw to exit and save at same time
  12.  
  13. C Formatting -
  14.   - #include <headerfile.h>
  15.     * This adds a premade library of functions to use
  16.     * goes at top
  17.  
  18.   - int main() { return 1; }
  19.     * This is the main function. It has all of the code you want ran first
  20.  
  21.   - Function(Argument1, Argument2);
  22.     * Dont Forget That Fucking Semicolon
  23.  
  24. How a C program Works -
  25.   - Algorithm
  26.     * Step by step instructions
  27.     * Computers need very specific instructions
  28.  
  29.   - Functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  30.     * Block of code that can be repeated over and over
  31.     * Function definition example
  32.  
  33.       void example(int number) { // Function definition
  34.           number++;// Adds 1 to number varitable
  35.           printf("%d\r\n", number); // Printf function Call
  36.           return; // Return VOID datatype
  37.       }
  38.  
  39.     * Calling example function
  40.       - example(5);
  41.       - the 5 is called argument
  42.       - function adds 1 to 5 and prints to screen then exits function
  43.  
  44.     * Return
  45.       - return is called when you want to exit function
  46.         > can be placed anywhere in function
  47.  
  48.       - can return any data type (char, int, float, etc)
  49.    
  50.     * Datatypes
  51.       - A datatype is a type of data like a number or a string
  52.       - There are datatypes located at begining of functions
  53.         > This datatype is for defining the type of data that gets returned
  54.  
  55.       - Char datatype
  56.         > Also refered to as a string
  57.         > Different Types of char
  58.           * char string1[size]
  59.           * char *string2;
  60.       - Int datatype
  61.         > Integer or whole number
  62.  
  63.       - Float datatype
  64.         > Any real number aka numbers with decimals
  65.  
  66. Basic Unix/Linux -
  67.     * Linux is based of unix
  68.     * Terminal/bash are more used in unix/linux than windows
  69.     * C and unix are connected
  70.       - C was originaly designed for unix
  71.    
  72.     * Directory = folder
  73.     * Basic Commands
  74.       - pwd returns the current working directory (CWD)
  75.       - ls lists everything in your current directory
  76.       - cd <directory> changes CWD to first argument
  77.       - cat <File Path> reads files and prints to screen
  78.       - Flags
  79.         > Flags are arguments passed to programs with -
  80.         > ex1) ls -a
  81.           * lists everything including hidden folders
  82.  
  83.         > ex2) ls -l
  84.           * lists the long version of ls
  85.  
  86.       - Directory
  87.         > Absolute Path
  88.           * From the very begining
  89.           * Use / to define as Absolute path
  90.           * Ex) cd /root
  91.  
  92.         > Relative Path
  93.           * Path relative to cwd (current working directory)
  94.           * Ex) cd ..
  95.  
  96.         > Root directory
  97.           * The begining of all directory branches
  98.           * /
  99.  
  100.         > Home directory
  101.           * The directory where your users files are kept
  102.           * First directory when opening terminal
  103.           * ~/
  104.        
  105.       - Playing With files
  106.         > touch <File Path>
  107.           * Creates a file
  108.           * touch main.c
  109.  
  110.         > mv <File Path> <To>
  111.           * Moves files
  112.           * mv main.c /tmp/main.c
  113.  
  114.         > rm <File Path>
  115.           * Removes Files
  116.           * rm main.c
  117.  
  118.       - Auto Completion
  119.         > You can auto complete commands by typing enough characters and press tab
  120.      
  121.       - Echo
  122.         > prints text
  123.         > ex) echo "Hello World"
  124.         > Echo to file
  125.           * ex) echo "Hello World" > filename
  126.           * Will overwrite everything in file
  127.  
  128.         > Echo to file appending
  129.           * ex) echo "Hello World" >> filename
  130.           * Instead of overwriting it appends or adds to file
  131.  
  132.       - Less
  133.         > ex) less <File Path>
  134.         > Shows 1 page of data from file at a time
  135.         > Useful when theres alot of data in a file
  136.  
  137. Basics Of C -
  138.     * Format
  139.        - Spacing
  140.          > C is a space insensitive language
  141.          > Used for clarity and ease of reading
  142.        - Also called syntax
  143.  
  144.     * Variatables
  145.        - Non case sensitive
  146.        - Declaring Varitables
  147.          > Ex) int x;
  148.  
  149.        - Initializing Varitables
  150.          > Ex) x = 5;
  151.          > stores the integer 5 in varitable x
  152.  
  153.        - Using Varitables
  154.          > Ex) int y = x / 2;
  155.          > This initializes the varitable y as x divided by 2
  156.        - Expression
  157.          > Anything that will evaluate to a single value
Add Comment
Please, Sign In to add comment