Amazon

Tuesday, June 7, 2016

Assembly Language: Simple, Short, and Straightforward Way of Learning Assembly Programming

Assembly Language:  Simple, Short, and Straightforward Way of Learning Assembly Programming


Chapter 1 - Introduction to Assembly Language

This chapter presents a brief introduction in assembly and the basic needed concepts in starting assembly programming to solve computer science related problems.

What is Assembly Language?
Assembly language is a low-level and the most basic programming language available for any processor. In assembly, programmers works directly on operations implemented on the computer's processor. Due to the nature of assembly language, it lacks high-level programming convenience since its far from human language like other high-level programming languages does. With assembly language, instructions like JMP @X, MOV AH, 09D, JNZ, DEC and many others are the codes that programmers deal with. At first glance, this codes does not represent any English like words, so learning assembly language can be quite a challenge for beginners. These are mnemonic codes that represents instructions and unlike other programming languages, in assembly, a certain code can represent several instructions which makes it more difficult.
Any computer has exactly two things on its foundation, a CPU and some Memory. These two makes computer programs run. The CPU reads the numbers one at a time, decodes them, and does what the numbers say, while the memory acts as the temporary storage location for the CPU. In assembly programming, programmers will deal with instructions implemented directly on the CPU and memory.

In the CPU Registers (for 32 bit), the 32 bit is the leftmost part of the register and the 16 bit is the rightmost part. Also the 16 bit are divided into two parts, the higher 8 bit and the lower 8 bit. Figure 1.1 presents the leftmost and rightmost illustration. All sample assembly codes and programs in this book uses only the 16 bit registers.

Figure 1.1 - Leftmost and rightmost composition of a register

1.  General Purpose Register
Figure 1.2 presents the general purpose registers which are available to the programmer.

Figure 1.2 - General purpose registers

As presented in figure 1.2, AX/EAX and DX/EDX both are used for input/output operations and AX/EAX and BX/EBX are also used for arithmetic computation. Note that AX, BX, CX, and DX are the 16 bit versions and EAX,EBX, ECX, and EDX are the 32 bit versions. Figure 1.3 presents the 32 bit and 16 bit areas of the general purpose registers.

Figure 1.3 - 32 bit and 16 bit composition

As presented in figure 1.3, the 16 bit registers are compose of two parts, the higher 8 bit and the lower 8 bit. The register AX comprises of AH (higher 8 bit) and AL (lower 8 bit), and so with the remaining 16 bit registers.

2. Segment Registers
Segments are specific areas defined in a assembly program for containing data, code and stack. There are three main segments which are:
2.1 Code Segment or CS Register contains all the instructions to be executed. A 16-bit Code Segment register stores the starting address of the code segment;
2.2 Data Segment or DS Register contains data, constants and work areas. A 16-bit Data Segment register stores the starting address of the data segment; and
2.3 Stack Segment or SS Register contains data and return addresses of procedures or subroutines. It is implemented as a 'stack' data structure. The Stack Segment register stores the starting address of the stack.

3. Pointer Registers
The 32 bit counterpart of pointer registers are EIP, ESP, and EBP registers and corresponding 16 bit counterpart are  IP, SP, and BP. There are three categories of pointer registers which are (the following focuses on 16 bit only):
3.1 Instruction Pointer (IP) is the 16 bit IP register which stores the offset address of the next instruction to be executed. IP in association with the CS register (as CS:IP) gives the complete address of the current instruction in the code segment.
3.2 Stack Pointer (SP) is the 16 bit SP register which provides the offset value within the program stack. SP in association with the SS register (SS:SP) refers to be current position of data or address within the program stack.
3.3 Base Pointer (BP) is the 16 bit BP register which mainly helps in referencing the parameter variables passed to a subroutine. The address in SS register is combined with the offset in BP to get the location of the parameter. BP can also be combined with DI and SI as base register for special addressing. Figure 1.4 presents the Pointer Registers.

4. Index Registers
The 32 bit counterpart of  index registers are ESI and EDI, and their 16 bit counterpart are SI and DI. Index Registers are used for indexed addressing and sometimes used in addition and subtraction. The two sets of index pointers are:
4.1 Source Index (SI) which is used as source index for string operations.
4.2 Destination Index (DI)  which is used as destination index for string operations.
Figure 1.5 presents the Index Registers.

5. Control Registers
Combining the 32 bit instruction pointer register and the 32 bit flags register are considered as the control registers. Many instructions involve comparisons and mathematical calculations may change the status of the flags and some other conditional instructions test the value of these status flags to take the control flow to other location. The common flag bits are:
5.1 Overflow Flag (OF) indicates the overflow of a high-order bit (leftmost bit) of data after a signed arithmetic operation.
5.2 Direction Flag (DF) determines left or right direction for moving or comparing string data. When the DF value is 0, the string operation takes left-to-right direction and when the value is set to 1, the string operation takes right-to-left direction.
5.3 Interrupt Flag (IF) determines whether the external interrupts like keyboard entry and others are to be ignored or processed. It disables the external interrupt when the value is 0 and enables interrupts when set to 1.
5.4 Trap Flag (TF) allows setting the operation of the processor in single-step mode. The DEBUG program we used sets the trap flag, so we could step through the execution one instruction at a time.
5.5 Sign Flag (SF) shows the sign of the result of an arithmetic operation. This flag is set according to the sign of a data item following the arithmetic operation. The sign is indicated by the high-order of leftmost bit. A positive result clears the value of SF to 0 and negative result sets it to 1.
5.6 Zero Flag (ZF) indicates the result of an arithmetic or comparison operation. A nonzero result clears the zero flag to 0, and a zero result sets it to 1.
5.7 Auxiliary Carry Flag (AF) contains the carry from bit 3 to bit 4 following an arithmetic operation; used for specialized arithmetic. The AF is set when a 1-byte arithmetic operation causes a carry from bit 3 into bit 4.
5.8 Parity Flag (PF) indicates the total number of 1-bits in the result obtained from an arithmetic operation. An even number of 1-bits clears the parity flag to 0 and an odd number of 1-bits sets the parity flag to 1.
5.9 Carry Flag (CF) contains the carry of 0 or 1 from a high-order bit (leftmost) after an arithmetic operation. It also stores the contents of last bit of a shift or rotate operation.
Example programs used in this book will not cover the above mentioned flags.


Chapter 2 - Our First Assembly Program

This chapter gives a quick glimpse on coding instructions in assembly. This chapter deals with assembler installation, writing codes, and running our very first assembly program.

Assembly Program Structure
Codes in assembly language are not case sensitive. The instruction MOV and mov means the same. In this book all reserved words and labels are coded in uppercase and all other user-defined codes are in lower case for readability purpose.

Fundamentals of Assembly Instructions
An instruction is a statement that is executed by the processor at runtime after the program has been loaded into memory and started. An instruction format contains three basic parts:
1. Mnemonic Code (required)
2. Operand(s) (usually required)
3. Comment (optional)

Figure 2.1: Assembly instructions usual format

Mnemonic Code
The mnemonic code is a short word that identifies the operation carried out by an instruction.

Operands
The operands are instructions which could have between zero to three operands, each of which can be a register, memory operand, constant expression, or I/O port.

Comments
Comments are a short description of the codes purpose. A way for the programmer to communicate information about how the code works to a person reading the source code.

Example 1: MOV AH,9D     ;Displays string
Explanation: MOV is an example of a mnemonic code instruction in assembly. The instruction MOV requires two operands separated by comma. We can say that AH is the first operand and 9D is the second operand. ;Display string is the comment. Comments are ignored by the assembler and will not affect the output of the program. Comments are used as internal documentation for the programmers reference of what the code does. It is a good practice in assembly to add comments as assembly codes does not usually represent English words.
Example 2: INT 21H    ;Calls DOS service
Explanation: INT is another example of a mnemonic code instruction in assembly. The instruction INT requires only one operand and in this example 21H is the operand. ;Call Dos service is the comment.

The MOV instruction appears to be shorthand for the word "Move". This makes a lot of sense as this instruction move from source to destination. However, the MOV instructions does not really moves the value from the source to the destination, instead it copies the value of the source to the destination. The syntax is presented in figure 2.2

Figure 2.2: Format of the MOV instruction

In figure 2.2, the destination can either be a register or memory address, and the source can be a register, memory address, or immediate value.
Example: MOV AH, 9D
Explanation: In the  example, it copies the source with the value 9D (D means decimal),  to the destination Register AH. This means that AH now holds the value 9D.

INT stands for interrupt. INT is an assembly language instruction for x86 processors that generates a software interrupt. Figure 2.3 presents the syntax of the INT instruction.

Figure 2.3: Format of the INT instruction

Example: INT 21H
Explanation: The example calls the software interrupt 21H (H means Hexadecimal) which is the DOS service. This usually returns the program to DOS. Other software interrupts and mnemonic codes are discussed in the succeeding chapters of this book.
The assembly program structure can be best explained with example.  Figure 2.4 is a sample program that prints the word "Hello World!" into the screen.



Note that the numbers in the leftmost part are just line numbers, hence not a part of the program code.

;<Code listings in Figure 2.4 - START>
.MODEL SMALL
.STACK
.DATA
Message DB "Hello World!$"
.CODE
MAIN:                   ; Below are comments
MOV DX,OFFSET Message ; Offset of Message is in DX
MOV AX,SEG Message   ; Segment of Message is in AX
MOV DS,AX            ; DS:DX points to string
 
MOV AH,9D            ; Function 9D displays string
INT 21H              ; Calls dos service
 
MOV AH, 4CH          ; Code to terminate the program
INT 21H              ; Calls dos service
END MAIN
;<Code listings in Figure 2.4 - END>

Explanation of code listings in figure 2.4
The ";" <semi-colon> is for comments for each line wherein anything that follows the ";" are ignored by the assembler, hence it will not affect the output of the program.
Line 1: .MODEL
It is an Assembler directive that defines the memory model to use in the program. Basically, memory models defines how big the program is. The bigger the program, the bigger model should be defined. The different memory models in assembly are:
a. TINY. This means that there is only one segment for both code and data. This type of program can be a .com file;
b. SMALL. This means that by default all code is place in one segment and all data declared in the data segment is also placed in one segment which means that all procedures and variables are addressed as NEAR by pointing at offsets only. SMALL is the MODEL that were used for all sample programs in this book;
c. COMPACT. This means that by default all elements of code are placed in one segment but each element of data can be placed in its own physical segment which means that data elements are addressed by pointing at both at the segment and offset addresses. Code elements (procedures) are NEAR and variables are FAR;
d. Medium. This is the opposite to compact. Data elements are NEAR and procedures are FAR;
e. Large. This means that both procedures and variables are FAR. It is needed to point at both the segment and offset addresses; and
f. FLAT. This isn't used much as it is for 32 bit unsegmented memory space. For this, DOS extender is needed. This is what is needed to be used  in writing a program to interface with a C/C++ program that used a DOS extender such as DOS4GW or PharLap.

Line 2: .STACK
It is an Assembler directive that reserves a memory space for program instructions in the stack. This directive is used for stack based programs which is discussed in the succeeding chapters of this book.

Line 3: .DATA
It indicates that the data segment starts here and that the stack segment ends there. This directive is where we declare and/or assign value to a storage similar to variable declaration and definition (assigning value to a variable) in high-level language.

Line 4: Message DB "Hello World!$"
Message is the variable name declared (user-defined) with a memory directive (define directive) of DB which stands for DefineByte (used for all programs in this book), and the value assigned to the variable Message is "Hello World!". The $ <dollar sign> is a string terminator, which means that it will not be printed in the screen. If $ is miss out, it will result to random characters printed on the screen, since the end of the string is not defined. The list of memory-directives (define directives) is presented in table 2.1


Enjoyed the reading? 

The following are the entire contents:


1.1 What is Assembly Language?
1.2 CPU REGISTERS
1.2.1 General Purpose Register
1.2.2 Segment Registers
1.2.3 Pointer Registers
1.2.4 Index Registers
1.2.5 Control Registers
2.1 Assembly Program Structure
2.1.1 Fundamentals of Assembly Instructions
2.1.2 The MOV instruction in Assembly
2.1.3 The INT instruction in Assembly
2.1.4 Reserved words in assembly
2.2 Running our first Assembly program
2.2.1 How to install TASM?
2.2.2 Writing the Assembly Program Codes
2.2.3 Compiling (Assembling), Linking and Running the Program              
3.1 Simplified Segment Directives
3.2 Output Routines
3.3 Input Routines
4.1 Introduction to Arithmetic Instruction
4.2 The ADD Instruction (Addition)
4.3 The SUB Instruction (Subtraction)
4.4 The INC Instruction (Increment)
4.5 The DEC Instruction (Decrement)
4.6 The IMUL and MUL Instructions (Multiplication)
4.7 The IDIV and DIV Instructions (Division)
4.8 Handling numeric data
4.8.1 Algorithm in printing 2 digit number
4.8.2 Algorithm in printing 3 digit number
4.8.3 Algorithm in accepting 2 digit number
4.8.4 Algorithm in accepting 3 digit number
5.1 Conditional Control
5.1.1 Conditional Jumps
5.1.2 Unconditional Jump
5.2 Loop Control
5.2.1 Conditional Loop
5.2.2 Counter Controlled Loop
6.1 What is Stack?
6.1.1 PUSH operation
6.1.2 POP operation
6.2 Stack Simulation
6.3 Stack Oriented Program
7.1 Defining a Procedure
7.2 Calling a Procedure
7.3 Procedure Oriented Program
8.1 OddEven Program
8.2 Legal Age Program
8.3 Alphabet Program

List of sample programs:


You may read the entire contents at https://www.amazon.com/dp/B01GQE4DS8








My Book Listings

Greetings!
 The following are my book listings available for purchase at amazon.com. Click the link and get redirected.

 1.


            The Student Information Source File is available at a minimal fee of $0.99. Click Donate and get redirected afterwards.


 2.



3. 


           The sample source files is available here at minimal fee of $0.99. Click Donate and get redirected afterwards.



4.




5.


C language Programming: Simple, Short, and Straightforward Way of Learning C Language Programming

  The sample source files is available here at minimal fee of $0.99. Click Donate and get redirected afterwards.




6.


C++ Programming Language: Simple, Short, and Straightforward Way of Learning C++ Programming

  The sample source files is available here at minimal fee of $0.99. Click Donate and get redirected afterwards.


Friday, May 20, 2016

SAP Financial Accounting (FI) Configuration Plan for the Implementation of ERP System

SAP Financial Accounting (FI) Configuration Plan for the Implementation of ERP System in a Restaurant

This is an example of a research study in regards to SAP FI - Financial Accounting Configuration Plan for a Restaurant. It comprise of a thesis format that follows ACM standard covering four major sections including the background of study, methodology, presentation of findings, and conclusions and recommendations. The book study covers a complete configuration plan of System, Application, and Products (SAP) Financial Accounting (FI) module of a restaurant. The objective of the research study is to develop a financial accounting configuration plan for the implementation of Financial Accounting module of SAP ECC 6.0 an ERP System in a Restaurant. Relative to the aim, this study sought to identify what are the configuration requirements that shall be considered in the Financial Accounting along the areas on organizational structure; processes; and financial Accounting data, to identify the major issues and challenges related to ERP implementation, and to determine the ICT infrastructure that shall support the ERP implementation. A complete reference and example of a research output for Computer Science and Information Technology research study majoring in enterprise track. TO GOD BE THE GLORY!

Rational/Background of the Study
Enterprise Resource Planning (ERP) system is an integrated set of programs that supports the core organizational activities such as manufacturing, logistics, finance, accounting, sales, marketing, and human resources.  An ERP system can be used by different departments in an organization to share data and knowledge, reduce costs, and improve the management of the business processes (Ledlum, 2010).

The ERP solution incorporates the practical systems used by organizations to manage the basic commercial functions of their business, such as: planning, inventory/materials management, purchasing, manufacturing, finance, accounting, human resources, marketing and sales, services etc (Holtz, 2013).

There are different ERP Systems provider available in the market, and one of the leading ERP system provider is the System, Applications, and Products (SAP) ERP. Since SAP-ERP has several modules, one of the most important module that needs to be configured is the SAP Financial Accounting (FI) module. This financial accounting module helps employees to manage data involved in any financial and business transactions in a unified system. SAP FI incorporates with other SAP modules such as SAP SD, SAP MM, SAP PP, Payroll for better work results (Wagner & Weidner, 2013).

SAP FI also has several sub-modules which includes  General Ledger, Accounts Payable, Accounts Receivable, Special Purpose Ledger, Bank Accounting, and Asset Accounting. The General Ledger contains a listing of the transactions effecting each account in the Chart of Accounts and the respective account balance. A Substantive and important integration between Sales and Distribution (SD) and Financial Accounting (FI). substantive and important integration between Materials Management (MM) and Financial Accounting (FI). Purchase and goods receipt activities in MM generate FI journal entries.
    
SAP ERP provides many advantages and benefits such as flexibility, customized solutions, module integration, continuous support, and reduces human effort. With all the benefits that SAP ERP offers, the researcher decided to propose configuration of Financial Accounting (FI) using SAP ERP at Health Restaurant. This study aimed at configuring a Financial Accounting (FI) module of an Enterprise Resource Planning System using SAP ECC 6.0 for Health Restaurant.



Summary
This study aimed to develop a financial accounting configuration plan for the implementation of Financial Accounting module of SAP ECC 6.0 an ERP System in Health Restaurant. Relative to the aim, this study answered the following:
1. What are the configuration requirements that shall be considered in the Financial Accounting along the areas on:
a. organizational structure;
b. processes; and
c. financial Accounting data?

2. What are the major issues and challenges related to ERP implementation?

3. What ICT infrastructure shall support the ERP implementation?

Findings
In relation to the research problems, the following are the findings of the project study:

1. The configuration requirements for FI module of Health Restaurant are as follows:
a. Health Restaurant currently has three (3) branches, but has only one (1) or centralize financial management;
b. Financial management is being done in a centralized scheme with branch with the code 100  as the main branch, on which all activities and transactions related to financial accounting are course thru to it; and,
c. The structure of financial accounting of Health Restaurant includes details such as cash flows including supplies, materials, salaries, collections;

2. The major issues and challenges related to the ERP implementation of Health Restaurant includes being a business established on the year 2009, its business processes and operations are still on its early and improving stage, and also the difficulty with overseeing three branches from different municipalities/cities in regards to transfer of data and documents.

3. The ICT infrastructure of Health Restaurant met the minimum requirements to implement SAP ERP, and has also the capacity to avail the recommended requirements.

Conclusions
Based on the findings of the study, the following conclusions were derived:

1. The requirements for configuring SAP ECC 6.0 FI Module along the areas on:
a. Organizational Structure. The organizational structure of Health Restaurant poses great challenge in configuring SAP ERP as the company had just started in year 2009 and still on the process of improving its organizational structure;
b. Processes. SAP FI Module of Health Restaurant offered more transparency and faster accounting procedures and provided reports for decision making purposes; and,
c. Financial Accounting Data. In consideration of the confidentiality of data for the accounting records of Health Restaurant, SAP FI Module can still handle assumed information and can still be configured to be flexible and be able to adopt changes as deemed necessary.

2. The issues and challenges related to ERP implementation includes the organizational structure and business processes which are not yet well defined given that the company just started year 2009, together with the difficulty with overseeing three branches from different municipalities in regards to transfer of data and documents. However, since ERP systems are one of the most popular business management systems, providing benefits of real-time capabilities and seamless communication for many organizations, the stakeholders supported the study, hence it is therefore concluded that despite the challenges and issues opposing the implementation of ERP system for Health Restaurant, successful configurations still took place with utmost consideration of the identified issues and challenges.

3. The ICT infrastructure to support ERP implementation covers Hardware and Software requirements. Health Restaurant current info tech resources when it comes to the hardware and software met the minimum requirements, and with the integration of SAP FI module, Health Restaurant will avail the recommended ICT Infrastructure of the SAP System.

Recommendations
Based on the findings and conclusions of the study, the following recommendations are offered:
1. The implementation of SAP FI module in Health Restaurant shall be considered as the first step in improving automated system using SAP. Configuration of  other FI sub-modules such as FI-BL, FI-TV, FI-AA, and FI-FM are highly recommended for faster, reliable, and more accurate reports. Also, configurations and implementation of other modules such as CO, SD, and MM along with the FI Module is highly recommended.

2. It is also recommended to add customization for the Health Restaurant  specifically to its reporting format thru the use of ABAP programming language in order to produce a custom and personalized interfaces meant to adopt to the requirements of the local government where Health Restaurant  is currently operating.

3. Continuous research is recommended as SAP versions are also being updated from time to time and that information technology is an endless cycle as well as further validation on every implementation being undertaken. Look for new techniques and technologies that would be more appropriate for the implementation of SAP System in Health Restaurant.



To download the complete content of this study, visit my book at https://www.smashwords.com/books/view/637891

Thursday, May 19, 2016

C Programming Tutorials

C programming is the best programming language intended for beginning programmers. It allows anyone to learn the basics concepts of programming from program statements, data types, variables, control structures, functions, and many more. Below are the list of topics meant for beginners.

Download the the following files. Please keep this BLOG RUNNING. Wait for the ads to load, then Click Skip add at upper right.

FOR .DOCX FILES:


FOR .PDF FILES:

File Management in C Language

File Management in C Language

Please keep this BLOG RUNNING. Wait for the ads to load, then Click Skip add at upper right.

Title: FILE MANAGEMENT IN C LANGUAGE
Ø  Download the .Docx Format of this article. Click HERE

Ø  Download the .Pdf Format of this article. Click HERE



PART A - File management in C
v  Introduction
·         C supports a number of functions that have the ability to perform basic file operations, which include:
1.      Naming a file
2.      Opening a file
3.      Reading from a file
4.      Writing data into a file
5.       Closing a file
v  File operation functions in C:
           
Function Name
Operation
fopen()
Creates a new file for use
Opens a new existing file for use
Fclose()
Closes a file which has been opened for use
getc()
Reads a character from a file
putc()
Writes a character to a file
fprintf()
Writes a set of data values to a file
fscanf()
Reads a set of data values from a file
getw()
Reads a integer from a file
putw()
Writes an integer to the file
fseek()
Sets the position to a desired point in the file
ftell()
Gives the current position in the file
rewind()
Sets the position to the begining of the file

v  Defining and opening a file:
·         The general format of the function used for opening a file is
            SYNTAX:
                        FILE *fp;
          fp=fopen(“filename.ext”,”mode”);

o   The first statement declares the variable fp as a pointer to the data type FILE. File is a structure that is defined in the I/O Library.
o   The second statement opens the file named filename.ext and assigns an identifier to the FILE type pointer fp. This pointer, which contains all the information about the file, is subsequently used as a communication link between the system and the program.
                        The second statement also specifies the purpose of opening the file.
o  The mode does this job. The modes are:
mode
Meaning
r
Opens the file for reading. If the file doesn't exist, fopen() returns NULL.
w
Opens the file for writing. If a file of the specified name doesn't exist, it is created. If a file of the specified name does exist, it is deleted without warning, and a new, empty file is created.
a
Opens the file for appending. If a file of the specified name doesn't exist, it is created. If the file does exist, new data is appended to the end of the file.
r+
Opens the file for reading and writing. If a file of the specified name doesn't exist, it is created. If the file does exist, new data is added to the beginning of the file, overwriting existing data.
w+
Opens the file for reading and writing. If a file of the specified name doesn't exist, it is created. If the file does exist, it is overwritten.
a+
Opens a file for reading and appending. If a file of the specified name doesn't exist, it is created. If the file does exist, new data is appended to the end of the file.

            EXAMPLE:
                        FILE *p1, *p2;
          p1=fopen(“data.txt”,”r”);
          p2=fopen(“results.txt”,”w”);
           
            ANALYSIS:
o   In these statements the p1 and p2 are created and assigned to open the files data and results respectively the file data is opened for reading and result is opened for writing.
o   In case the results.txt file already exists, its contents are deleted and the files are opened as a new file. If data.txt file does not exist error will occur.


v  Closing a File
·         The input output library supports the function to close a file; it is in the following format. SYNTAX:
            fclose(file_pointer);

·         A file must be closed as soon as all operations on it have been completed.
·         This would close the file associated with the file pointer.
                        EXAMPLE:
                             …
              FILE *p1 *p2;
              p1=fopen (“Input”,”w”);
              p2=fopen (“Output”,”r”);
               …
              …
              fclose(p1);
              fclose(p2)

                        ANALYSIS:
o   The above program opens two files and closes them after all operations on them are completed, once a file is closed its file pointer can be reversed on other file.

v  getc and putc functions (Reading and Writing)
·         The getc and putc functions are analogous to getchar and putchar functions and handle one character at a time.
·         The putc function writes the character contained in character variable c to the file associated with the pointer.
·         Similarly getc function is used to read a character from a file that has been open in read mode.
SYNTAX:
     putc(c,fp1);
     c=getc(fp2).

            EXAMPLE:
     #include< stdio.h >
     main()
          {
          file *f1;
          printf(“Data input output”);
          f1=fopen(“Input”,”w”);       /*Open the file Input*/

          while((c=getchar())!=EOF)    /*get a character from key board*/
               putc(c,f1);             /*write a character to input*/
          fclose(f1);                  /*close the file input*/

          printf(“nData outputn”);
          f1=fopen(“INPUT”,”r”);       /*Reopen the file input*/
          while((c=getc(f1))!=EOF)
          printf(“%c”,c);
          fclose(f1);
          }
            ANALYSIS:
o   The program shows the use of file operations.
o   The data entered through the keyboard and the program writes it. Character by character, to the file input.
o   The end of the data is indicated by entering an EOF character, which is control-z. the file input is closed at this signal.

v  The getw and putw functions (Reading and Writing)
·         These are integer-oriented functions. They are similar to getc and putc functions and are used to read and write integer values.
·         These functions would be usefull when we deal with only integer data. The general forms of getw and putw are:
            SYNTAX:
                        putw(integer,fp);
          getw(fp);
                 
PART B - File Oriented Program
v  A demonstration of using file management function
- The program will accept 5 integer numbers from the user and will write it to the DATA file.
- If the entered number is even, it will be written into the EVEN file.
- if the entered number is odd, it will be written into the ODD file.
            #include< stdio.h >
            main() {
                  FILE *f1,*f2,*f3;
                  int number, I;
                  printf(“Write Contents of the DATA file: \n”);
                  f1=fopen(“DATA”,”W”);
                  for(I=1;I< 5;I++){
                        scanf(“%d”,&number);
                        if(number==-1)
                              break;
                        putw(number,f1);
                        }
                  fclose(f1);
                  f1=fopen(“DATA.txt”,”r”);
                  f2=fopen(“ODD.txt”,”w”);
                  f3=fopen(“EVEN.txt”,”w”);
                  while((number=getw(f1))!=EOF) {     /* Read from data file*/     
                         if(number%2==0)
                              putw(number,f3);        /*Write to even file*/
                         else
                               putw(number,f2);       /*write to odd file*/
                         }                     
                  fclose(f1);
                  fclose(f2);
                  fclose(f3);
                  f2=fopen(“ODD”,”r”);
                  f3=fopen(“EVEN”,”r”);
                  printf(“\nContents of the ODD file: \n”);
                  while(number=getw(f2))!=EOF)
                        printf(“%d%d”,number);
                  printf(“nnContents of the even file”);
                  while(number=getw(f3))!=EOF)
                        printf(“%d”,number);
                  fclose(f2);
                  fclose(f3);
                  }
SAMPLE OUTPUT:
   Write Contents of the DATA file:
   5
   2
   1
   3
   8
   Contents of the ODD file:
   5
   1
   3
   Contents of the EVEN file:
   2

   8


Workshop

          This Workshop provides quiz questions to help you solidify your understanding of the material covered, and exercises to provide you with experience in using what you've learned.

1)     Can I use drives and paths with filenames when using remove(), rename(), fopen(), and the other file functions?
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

2)     Can I read beyond the end of a file?
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

3)     What happens if I don't close a file?
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

 PART C - PROGRAM DEVELOPMENT - File management function oriented program

Conversion PROGRAM (10pts)
1.     The program will accept five (5) integer numbers from 1 to 5 (Set01) and 6-10 (Set02) from the user and will write the entered numbers into S1INPUT.txt (Set01) and S2INPUT.txt (Set02).
2.     The following will be conversion:
            1 = A               6 = F
            2 = B               7 = G
            3 = C               8 = H
            4 = D               9 = I
            5 = E                10 = J
The program will then write the converted values into S1OUTPUT.txt (Set01) and S2OUTPUT.txt Set02).
3.      NOTE: The program must check the user input, if out of ranged; it must not accept the value and should prompt the user.

Sample OUTPUT for S1:
            Enter Five integer numbers from 1-5:
            5
            2
            1
            1
            3

Contents of S1Input.txt                                Contents of S2Output.txt
            5                                                                      E
            2                                                                      B
            1                                                                      A
            1                                                                      A
            3                                                                      C


Please keep this BLOG RUNNING. Wait for the ads to load, then Click Skip add at upper right.

Title: FILE MANAGEMENT IN C LANGUAGE
Ø  Download the .Docx Format of this article. Click HERE


Ø  Download the .Pdf Format of this article. Click HERE