Adding relevante parts of the C language in to a mini manual. To have the information resumed and updated :
A basic file in C it uses the .c extension : mini_manual.c // any coding editor can create this file
A C program consist of this structure :
----------------------
#include <stdio.h> // system Libraries which are compiled
#include "standard_variables.h" // user librarys which are not compiled
// A library is a file that contain mainly other functions or variables.
char msg1; // Global variables outside main
int main() A function called main which is where the compiler\program uses as reference to know where things are or start.
{
char msg2; // local variables inside main
printf("Hello World!"); // Function call to display a msg
#include "menu.c" A include file to use funcionality directly.
// For example our menu is hevy complex and we don't want to edit all our projects that have a menu. We can just use\reuse the same menu include. When we edit the menu.c all our projects will be updated. We just need 1 updated in a file since all others link to that file. But in this case it will depend a bit on our planning. Lets say a change is needed for one project but not the others.
return 0;
}
---------------------------------
// As seen in previous example we have our libraries on the top of the file
#include <stdbool.h> // C99
#include <stdio.h> // header file type is "pre-processor" it is performed before .c files and uses .h extension in this case is a compiled system lib
#include "../includes/standard_variables.h" // user header file in a path above inside the includes folder. assumes a 2 folder structure (progs includes) comes out of 1ยบ folder to include a file in the "includes" folder.
// And variables that can be inside or outside main
char msg[]; // Declare a string in C dinamic size
char msg1; // single character C assume 1 character if no size is give
char msg2[10]; // assumes 10 max characters long string
int myAge = 43; - 2,147,483,648 to 2,147,483,647
float floating = 1.5 // floating values also called decimal
Short Byte and Boolen are not available but probably there are some kind of library to do this. If you plan to work with high amount of numbers may need better declaration because program may become to large in therms of memory use.
short value // Numbers from -32,768 to 32,767
byte value // Numbers from -128 to 127
boolean value // 1 to 0
Array
int int_array[3] = {"5", "8", "9"};
char string_array[3] = {"h", "k", "m"};
Arrays in C are not tha valuable since they don't allow mixed data.
Still a good aspect is that they can improve performance since they don't allow this.
Mix data
Structure declaration of mixed values .
struct My_Structure
{ int my_num; char my_letter;
};
File Manipulation
FILE *fptr
fptr = fopen(filename, mode);
FILE *fptr;
w - Writes to a file
a - Appends new data to a file
r - Reads from a file
fptr = fopen("filename.txt", "w"); // Create a filefclose(fptr); // Close the file
Librarys
#include <math.h> // Math functions library. it extends the basic funcionality of C width more functions.
ceil(1.4) // rounds up
floor(1.4) // rounds down
Loops
Repeats the same action X times.
Loop example in this case 5 times.
int i = 0; //
while (i < 5)
{
printf("%d\n", i); // \n is a symbol to represent new line
i++;
}
Pointers
Are important because they improve the performance, this is the reason why C is knowed to achive high level of performance. Because they allow us to manipulate the data in the computer's memory, this can reduce the code.
int* ptr_my_age = &my_age;
//