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.
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.
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;
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 email@example.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.
- Android Studio Articles – https://builditmasters.com/category/android-studio/
- Android Studio Firebase Tutorial – https://builditmasters.com/category/android-studio-firebase-tutorial/
- C Programming – https://builditmasters.com/category/programming/
- Flutter – https://builditmasters.com/category/flutter/
- GitHub Tutorials – https://builditmasters.com/category/github/
- Java Programming – https://builditmasters.com/category/java-programming/
- MERN / MEVN Stacks – https://builditmasters.com/category/mern_mevn_stacks/
- Tech News – https://builditmasters.com/category/tech-news/
- Theory Lessons – https://builditmasters.com/category/theory-lessons/
- Adobe Tutorials – https://builditmasters.com/category/adobe-tutorials/
- Best Website for Programming – https://builditmasters.com/category/best-website-for-programming/
- Different Programming Styles – https://builditmasters.com/category/different-programming-styles/
- Earn Money – https://builditmasters.com/category/earn-money/
- Social Word – https://builditmasters.com/category/social-world/