Learn File Handling & Pointers | C programming

Outcomes

After you reading this post you can learn how to create, update and process data files fro storing and reading data in C programming. So let’s start File Handling & Pointers | C programming.


File Handling & Pointers | C programming : File Handling

Files are used to store data permanently. because of when the program is terminates, data is lost. Let’s see how we are creating access file in C programming.

This is the format to create a access file,

File_Structure     file_pointer ;

ex -: FILE  *cfPtr ;

First we define the file structure. Then we assign a file pointer. That is the best way to create access files. After that let’s see how to open a file to write data.

cfPtr = fopen( “buildITMasters.dat” , “w” ) ; 

we write “w” in the above code, because we are going to write a file. If you want to read a file, you must assign “r”. See the description given below. You can learn file opening modes in there.

w = Create a file for writing

r = Open an existing file for reading

a = open or create a file.

r+ = open an existing file for update. ( reading and writing )

w+ = create a file for update.

So now we know how to create a file or read a file. Let’s see the example.

File Handling
File Handling

Pointers – File Handling & Pointers | C programming

Do you know what a pointer is? or Do you know how to use pointers in a C program? or Do you know how to apply pointers for a dynamic memory allocation? Okay if you know the answers to those all questions, you can leave from this post now. Because now I am going to write answers for the above questions. Let’s see the answers.


What is a pointer ? File Handling & Pointers | C programming

A pointer is a variable that hold a memory address. See the example given below.

What is a pointer ?
What is a pointer ?

So let’s see the format in declaring a pointer.

data_type   *pointer_name ;

ex -: int *osa , float *height

Once a pointer is declared it should be assigned with a memory address of the location to be pointed. Let’s see a example.

int size = 5;

int *sizePtr;

sizePtr = &size;

If you want to assign a variable to a pointer, you can do like that. Also you can initialized a pointer like this,

int *sizePtr = null;

So this is the end of this tutorial. If you have question send us an email to malimbadaosanda@gmail.com or Contact us. You can use repl.it to practice your knowledge.

Thank you. Make sure to leave a comment.

There are more articles from BuildITMasters. Follow the below link to refer.

Other articles from different categories.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x