Skip to main content

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

File types, Text and Binary in C

As discussed earlier the C language provides flexibility for the programmers to write file handling programs to store and process data. Such data files contain the data effectively in two formats. So, on the basis of the format structure of the files are of two types, Text File and Binary File.

Text File

In a text file a stream of characters are stored sequentially without any formatting. So, it is very simple to handle but direct access is not possible because any value or character is not stored after fixed number of bytes. Even though the numbers are stored in the form of characters only and the record length is not fixed if the records are stored. Again the records are also stored in the character format of the individual fields.

Similarly, since text files only process characters, generally they can only read or write data one character at a time. But the flexible C Language provides file handling functions to read and write formatted data and lines of text in a text file. But these functions again basically process data one character at a time. The normal functions used to handle the text file are getc(),fgetc(),fgets(), fputs(), putc(),fputc(),fscanf() and fprintf(). These functions transfer the character/s to and from the text file.

Depending on the requirements of the OS (Operating System), newline character may be converted to or from carriage-return/linefeed combination depending on the data is being written to, or read from, the file. Other character conversions may also occur to satisfy the storage requirements of the OS. These translations occur transparently and they occur while processing a text file.

Binary File

A binary file is not much different to a text file. It is also a collection of bytes. But the transfer of data is purely in the form of bytes as stored in main memory. Any number of bytes can be transferred at a time, in binary file. But the length of the bytes transferred is fixed. So, the binary files contain the data in fixed length record format. That is the reason they are more effective than text files. One important advantage of fixed length is that of accessing the record directly. The direct access is possible only in case of the binary files. It is basically because when a record is written to a binary file form the memory, the complete memory block is written. The number of bytes transferred is fixed. In the same manner when the data is read from the binary file the number of bytes is transferred to the memory at the provided address. The file handling functions provided to handle the binary files are fread() and fwrite(). This fixed length transfer is advantageous for direct access but the size of the file increases. So, in comparison to text files the binary files are advantageous in direct access at the cost of the size. Thus a selection of type of file is decided keeping the accessibility of data in mind.

A binary file is also referred to as a character stream but differ in the following ways:

• No special processing of the data occurs and each byte of data is transferred unprocessed to or from the disk.

• C Language places no constraints on the file, and it may be read from, or written to, in any manner.

Binary files can be either processed sequentially or randomly. The processing of a binary file using random access techniques involves moving the file pointer position to an appropriate place in the file before reading or writing data. This indicates a second characteristic of binary files; the binary files are generally processed using read and write operations simultaneously. For example, for the creation and processing a database file the best choice is a binary file. A record update operation will involve locating the appropriate record, reading the record into memory, modifying it in some way, and finally writing the record back to disk at its appropriate location in the file. These kinds of operations are common to many binary files, but are rarely found in applications that process text files.

The type of the file to be processed is decided at the time of opening a file. At the time of opening a file the mode of operation is mentioned indicating text file or binary file. The function fopen() provides the capability of opening a file. By default the file is opened in text mode. If the binary file is to be processed then it is explicitly defined as “b” along with the other required mode character ‘r’, ‘w’ or ‘a’.

When the file is opened the mode of operation is specified. It indicates the types of files “text” and "binary". The text file is advantageous in terms of size and the binary file in terms of random or direct access.

Comments

Popular Post

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows: Polynomial:      3x 3 -4x 2 +2x-9 Linked List: In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable. Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of