Skip to main content

Posts

Showing posts from December, 2018

Structure and Unions & Memory Allocation

Structure  Is a data type to store a group of data with various of data type. Structure Declaration 1.  struct name_structure {    dataType1 name_field1;    dataType2 name_field2;    … } name_variable_structure ; 2.  struct name_structure  name_variable_structure;  Accessing Structure Element of a structure can be accessed using dot operator struct mhs {   char nim[9];   char name[26];   float gpa; }; int main (){   struct mhs lia;   gets(lia.name); } Structure Initialization Syntax: struct struct_name variable = {value_1, …, value_m}; struct employee info = {1,"B. Smith"}; Array of Structure Structure data type can only contain one record. But real world problem needs group of records. So it's a structure inside a structure.  Example: struct Dob {   int date, month, year; }; struct Account {    int accountNo...

File Processing

File and Streams Streams, definition : To keep data from the keyboard saved at secondary storage such as a data file.  Streams is a sequence of character. File, When a C program run, there are 3 standard stream activated. 1. Standard Input Stream, controlling input stream from keyboard 2. Standard Output Stream, controlling output stream into the monitor 3. Standard Error Stream, controlling the error messaging All of these streams associated with a file. File Definition :  File is a collection of record Record is a collection of field Field is a block of byte Byte is a collection of bit File Operation, in C we perform 4 major operations on the file :  1. Creating a new file  Make a new text file to keep our data saved there 2. Opening an existing file When opening the file that has our data in it, we use,  The syntax for opening a file in standard I/O is: fptr = fopen("fileopen.txt","mode"); Mode is a feature that allow us...

Sorting And Searching

Sorting Sorting is needed to speed up the process of searching a data. There are two kinds of sorting :  ascending from the lowest to the highest. And descending from the highest to the lowest. Type of sorting : 1. Bubble sort, compares the value of the current data with the immediate next data and swap the according to the requirement and goes till the last element. 2. Selection sort , a selection of an element position from the start with the other rest of the element. Element are compared and exchanged depending on the condition and then selection position is shifted to the next position till it reaches to the end 3. Insertion Sort, one element from the top is selected and is compares to the other rest of the elements down the line and inserted to another position and rest of the elements are shifted accordingly. 4. Quick shot, it picks an element as pivot and partitions the given array around the picked pivot. 5.  Merge shot,  This t...

Function and Recursive

Function So, program is divided into modules. The modules in C programming language are execute using function. Function is a group of sentence that does a specific job. Function in C usually written above the int main() The benefit of using Function : 1. A huge program can be divide into smaller modules. 2. Easier to fix if there is a problem. 3. Easier to document Function Construction : return_type_value function_name  (  parameter-list  ) {    statement; } return-value-type :  data type of the value returned,  If not filled, then default data type will be used (integer) If return-value-type is void then the function will not return value Parameter-list : list of value sent from the function initiator (user) example :  int maximum ( int a,int b )    {      statement     } int : return value type of integer int a, int b : the parameter input by user statement : al...