Skip to main content

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 : 

  1. File is a collection of record
  2. Record is a collection of field
  3. Field is a block of byte
  4. 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 to read, write, or add the data inside the file.

3. Closing a file

Don't forget when we open a file we must end it with a close
The Syntax for closing a file is :

fclose(fptr); //fptr is the file pointer associated with file to be closed.

4. Write or read on the existing file

There are the most used mode when opening a file :
  • "r" "read" is used to read the data that is inside the file.
  • "w" "write" is used to overwrite the data if there is a file, or to make a new file if the file doesn't exist.
  • "a" "append" is used to add the data at the end if we want to add in a file.

Comments

Popular posts from this blog

Cloud Storage

Cloud Computing atau nama lainnya adalah Komputasi Awan adalah teknologi yang menjadikan internet sebagai tempat penyimpanan database, aplikasi dan masih banyak lagi. Layanan Cloud Computing 1. Software as a Service (SaaS) Layanan pemakaian teknologi mengenai pemakaian software yang telah disediakan contohnya : gmail, outlook mail 2. Platform as a Service (PaaS) Cloud Computing dapat menyewakan sistem operasi, database engine, framework aplikasi untuk menjalankan aplikasi yang kita buat. Contohnya : windows azure  3. Infrastructure as a Service (IaaS) Cloud Service dapat memberikan layanan infrastruktur IT. Contohnya CPU, penyimpanan data, memory dan lainnya dapat disewa.  Cloud Deployment Model Deployment model define the type of access to the cloud. Type of access : 1. Private cloud       - Single organization only       - Managed by the org or a 3rd party       - On ...

Summary Semester 1

Assignment #1  1. Compound Word Jojo has just learned about compound words, which occurs when two or more words are joined to make one longer word. For example the English word footpath, composed of two words "foot" and "path". She wants you to make one such word, given two words that make up the compound word. 2. Birthday Cinema * Jojo, Lili, and Bibi wants to treat their N friends. They want to treat their N friends to watch a movie. Each movie ticket cost 1 point. Luckily there is a promo, if you buy 2 tickets you get 1 for free. How many points do they need to spend to buy tickets for all of them. 3. Counting Number Lili has just learned how to count from 1 to n, while Jojo just recently learned how to use a calculator. When Lili counts from 1 to n, Jojo always adds the numbers that Lili mentions. Jojo asked for your help to check if he used the calculator correctly, he needs you to calculate the number he is supposed to get. 4. Boom...