Sunday, December 16, 2018

File Processing


• Stream definition :
          A sequence of character. All input and  output data is a stream. C sees file as a stream.
• File Definition :
There are 2 types of  File
      • Text File
          - Saved in a text format or ASCII File

Storage size depends on its data: 10000 needs 5 byte
Can be open using standard text editor application
- Or c:>TYPE file_name

• Binary File 
storing numerical data in affixed format in line with micro-processor format definition
(example: format sign-magnitude 2’s complement).

File is a collection of record
Record is a collection of field
Field is a block of byte
Byte is collection of bit



• How to open a File ?

Opening a File using fopen():
  FILE *fopen (const char *filename, const char *mode );
fopen() defined at <stdio.h>
fopen() return a pointer to the start of a buffer area. Null will be returned if file unable to open.
Types of mode you can use

     Mode        Description

r”       Opening a file to be read.
w”      Creating a file to be written.
a”       Opening a File for data append.
r+”     Opening a File for read/write.
w+”    Creating file for read/write.
a+”     Opening a File for read/append
“rb”      Opening a File (binary) to be read.
“wb”     Creating a file (binary) for write operation.


Don't forget to close your opened file by using
int fclose (FILE *stream);

Structures, Union, and Memory Allocation

Structure Definition :

• Structure is a data type to store group of data with various of data type
• Structure component called member/field/element.
• Heterogeneous (various element data type)
• Structure in other programming language also called record
• Nested Structure is a structure with one of its element is another structure.
Structure Declaration :

Syntax
struct name_structure {
    dataType1 name_field1;
    dataType2 name_field2;
    …
};

Variable can be defined at declaration time
struct name_structure {
  dataType1 name_field1;
  dataType2 name_field2;
} name_variable_structure ;

Structure variable declaration
struct name_structure  name_variable_structure; 

Union Definition :
• Union is used for memory join. By using union, a memory location can be assigned for two or more variable with different data types
• Memory capacity used by union is the largest capacity used by any element of the union

Union Declaration :
Union Data Declaration
union name_union{
         typedata1   name_var1;
         typedata2   name_var2;
         ....
}   name_var_union;

Union Variable Declaration
union   name_union       name_var_union;

Memory Allocation Definition :
• Memory allocation:
  acquiring some memory space (RAM) managed by the OS to be used by a program.
• Memory de-allocation:
  releasing memory space (RAM) back to the OS.

Sunday, December 2, 2018

Recursive, Function, and Cloud


Function Definition:
Function Structure
 return-value-type  function-name( parameter-list )
 {
   statements;
 }

return-value-type:  
data type of the value returned
If not filled, then default data type will be used (default 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)



Recursive Definition:

Recursive is a function call inside a certain function calling itself
Recursive Function is suitable for recursive problem
Example :
 Factorial (n) or n! defined as follows :
 n! = 1, for n = 0;
 n! = n * (n-1)!, for n > 0
 4! = 4 * 3!
 3! = 3 * 2!
 2! = 2 * 1!
 1! =  1* 0!
 0! =  1
 Trace back : 4! = 1*2*3*4 = 24

Cloud Definition:
Cloud is an online-based storage used by user to store their data. There are 2 types of data
storage consist of offline-based storage and online-based storage. The examples of Cloud
storage company is iCloud, Microsoft OneDrive, Google Drive, and many more. In Cloud 
storage, there are Software as a Service (SaaS), Platform as a Service (PaaS), and
Infrastructure as a Service (IaaS).