 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. अब देख हैं, C-language video series. And this is lecture number 27, in which I will explain to you how we manage bulk data file handling. You will see that I will tell you the use of two functions, which are written here. First is F-read and second is F-write. With the help of these two functions, we will process binary files. So remember one more thing, whenever you process bulk data file type will be binary. In my previous videos, where I explained lecture number 26 and 25, I explained text file there. But now we have to manage large amount of data, so we will use binary file. And what I will explain to you is, reading, writing, array, into file, then structure and then array of structure. So we will discuss all these examples one by one. And if you have any doubt, then these are my details, on which you can communicate with me. Because after watching the videos, it is possible that you will have any particular doubt about how it happened or we did not understand it. So you can discuss with me. So let's start by implementing our first program, read array from user and store it into a file. So user will input an array and it will store it in the file. So DAF C++ compiler comes. So read array from user and store into file. So now let's include header files here, stdio.h, stdlib.h, then main function. In main function, now let's declare an array. For example, its size is 10, variable i. To open the file, we will have to make the file pointer. So I have already explained this. So those who have not seen the old videos, lecture number 26 and 25, you will get the full video series playlist link in the description of this video. So after watching lecture number 25 and 26, you will understand what we are discussing right now. So what is the file pointer, how it works, how it opens, I have explained it in detail. So now let's open the file. Then we have to input from user and store data in the file. So we have to write data in the file. It means if the file has not been created before, then there is no problem. We will create it and open it in w mode. So for example, I write the name of the file, array data, and I have named it .txt and we have to use the mode w. If I use only w, then it will be a text file. If I have attached b with w, then it will be a binary file. So now see, my .c file, test.c, if you see the title, then it is available in the demo folder of d drive. So if I write the name of the file directly, then this file will automatically be created in the demo folder of d drive. You want this file to be created at any other location. For example, suppose there is a folder named demo in e drive, and you want to create it in it. So you have to mention the proper path like this. So you have to write this for any other drive. And if your .c file is there, then you want to create another file. So you can directly open the file name .txt in binary mode. And as soon as we open the file, then we check the condition, fpw equals to null. So if the file pointer null is equal to null, then we have to print a message and not open file or exit. So now what will happen is that if the file cannot be opened for any reason, for example, you do not have sufficient amount of memory available or if there is any error in file creation, then in that case the file pointer will be null. So if the file pointer is null, then this error message will be displayed and the file will not be opened. So we used exit. Terminate the exit program there. Now I have to input from the user. So I have written enter values. Then we will implement a for loop. For loop will go for 10 times because we already know that we have to store 10 numbers. So I have written scanf percent d, m percent a of i. And when this will properly read the data, then we have to store it in the file. So to store it in the file, we will use fwrite. So first you have to use the name of the array. Then size of int comma 10 comma fp. So we have to understand what the four parameters will do. So this is the beginning address of an array. So I made an array video, an array pointer. So I had told you that name of array represents base address of the complete array locations. So if you use the name of the array, then the beginning address automatically provides it. So there is no need to put m percent. Then size of int means that the array we have created will have a particular element size of the integer. Because we have made an integer array. If this array was float, then you would have taken size of float. Then how many elements are there? It will tell you 10, that is quantity. And where to store it? It will tell you fp file point. And after storing it, you can use fclose fp. So in this way, we got input from the user through these statements. And we wrote it in the file through fwrite. So you can see that fwrite, bulk data, will store it in the file only once. There is no need to run a loop for it. So whenever the array structure or array of structure has to process the data through the file handling, then you can use fwrite or fread, which will read the data from the file. So I saved this file. Let's compile it and see if there is any error. There is no error in it. Now we will execute it. So first let's go to the d drive. In the d drive, there is a demo folder. There is no file available in the array. So when I execute it, you will see, that one file will be automatically created. So now I have to add values. 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. 10 values are added. The data is in the file. To check it, you will go to the demo folder of the d drive. See, the file is created in the array data. Now when I opened the text file, I told you in the previous video, when I opened the file, the data was in readable format. But you will see that you won't get it in readable format. Because we have stored the data in the binary format. So whenever you store bulk data, binary format is necessary so that the data can be easily managed. We can use size less to store the data. But the drawback is that the data we write in the file, we can't read it after opening it. It means that the array data.txt file I have made, when I want to read it, I will have to write a program for it. So that will be my next program. See, what I have solved, read array from user and store into a file. Next, read array from file and print on console. So if we modify this program and open the file in read mode, then the array we have written will be read and displayed on the console. Read array from file and print on console. So now we will open it in read mode. Things will remain the same till here. Now these statements will be removed. They will come after reading. See, first we have to read the data from the file. Now instead of f right, I will use function f read. Okay. How to read it? So I have passed the array. I have given the size of each element. How many elements are there? How to read it? So when f right was used, then fp was destination. When f read is used, then fp is source. Okay. Now I have written file contains. I have written nf, print f and after percent d, I have put comma. With this one element, all elements will be printed in one line. But after every element, a comma will be printed. So this program is completed. Now see, we will not input anything from the user. We will read the data from this file. And we already know that we have stored 10 elements in it. If there is more data, let's suppose you want to read 5 elements, you can also mention size 5. So it will depend. So execute. See, file contains 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. Automatically the data is read from the file. So I did not input anything. The data is automatically read from the file and it is printed. Now if I close this compiler. And the next day, I run this program in front of you. Even then this program will read the same data from that file. This is the benefit of file handling. Whatever we have stored in the file, we can process it anytime. So here you have also seen that the output of one program is also working for the other program. And the input output is permanently stored. We can access it anytime. So in real time, there is a requirement of such softwares where the user output generated is also stored. Now let's move ahead. We have to apply the same operation on the structure. So we will make two programs. First, read structure from user and store into file. And second, read structure from file and print on console. So we have to follow the same approach. But this time we are going to use structure. So read structure from user and store into file. So let's make a structure first. Again, let'sSONIFICER Uט le trent house and we can странize it and we can get the structure. So for that, तो वहाप को समच में आगा औगे ज़िश्वक्चर बस्तिकली कैसे खाम करता हैं ऑद नेम रोल लमबर लिट किया फिर नेम लिट किया नेम प्रोपर दीडो यसले मैंने, जो रोल लमबर किकि पाता हम अंटर्ठर्प्रेस करे आपनी वहस्षो जेत कैर के तो ch ने श्टोर करापी हैं अंद वाख्स रीवड़ करनेगे ले पूस्ट याप आम पूस्ट अज श्टोड वाख्स अब देटा रीवड़ हो गया बल्क देटा है अपने पास में रोल नमप्र हैं, ने में वाख्स येगी विरियवल हैस अब देटा फाईल में चलाज़ा है, में लिकोंगा f right अब देखो, ये जो s विरियवल में लेए श्टॉक्चर विरियवल बनाया क्या ये आरे हैं? नहीं, येग नोमल विरियवल है, आरे नहीं तो मैं आपको बताट है कि, आरे का नाम उसका बेसडरस बताता है, बत जो विरियवल आरे नहीं है, उस केस में आपको m% use करना बड़ेगा, तो जब याप एक सिंगल श्टॉक्चर रहीं तो आपको m% as लिखना बड़ेगा, अगे जा कर मैं आपको बतावगा, हम आरे अप श्टॉक्चर का भी प्रुग्रें में, तो इस केस में में m% use नहीं करोंगा, योगी अगे वापकर आरे आजा, बाखे सारे जीजे सेझे मैं, तो यापको मैं लिखना साईज अप श्टॉक्च्टॉडन, एक विरियबल एस ले वन, और कहा पे रहीट करना है, जब हम इसको एकजिकूट करेंगे, तो देखो ये मुसे पूच रहा है, रोल नमबर मैं डाला 101, में पूच रहा है, मैं डाला संजे, और माक्स मैं डाले 1000. जीखे डेटा फाई में चला लागा, कैसे पता चलेगा? देमो फोल्डर में जाओ, अपन करो, कुछ भी रीटेबल नहीं होगा, बाईनरी फाँम में, कुछ कुछ जीजे रीटेबल है, बड़ जरूरी नहीं है, क्या आपको हर चीज प्रोपर रीटेबल हो, तो इसको तो करता हैं, ख्लोस, अब हम चाता हैं, अब भी बन जाएगा सूर्स और तार्गेट बनेगा आज, म्ड़क अप पी से ड़ाएवूट्खर, किस में आज आज अएगा एज वेड़़़ल में, अज manor अज manor अज manor अज manor श़ब अ कितना शब लिच धेडा उठेगा जा जो एस श formulation of the structure & how much of quantity it is and how many is the structure अज manor अज manor उज manor अज manor अज manor अज manor अज manor अज manor अज manor तु आब हम पाईल कफीट मेनिश करें आरीआच च्चर ये तु पहले मै देटा रइट कर मुझ़ रउग रहुग फीट कर वगा तु मैंने या आच्चाईज मेशन कर दीटडी हें पूँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँँ� यह जीग़ग जीग़ग की अपी लिए तो भी लेग गे रूल लूलम्ड़ के बाग़ एक आप्टेप्टेस करनेगे लेग, फिर आमने लिका गेट येट येट येट सोभ अप आई ब येट लेग, और मागस को लिट ग़गा रानेगे लेग, आगेट स्कैन अप पोसर्थ � उस्ट्र्टर लिएब लेवाले केसे रहीत लोगा और उसे जाँद लेटा घैटा है और आ़र्योग स्ट्रक्चे केसे रहींत गोगा तो, आगर हहां धेमो फुलटर को फिरसे देखें वी यहान देखो स्स्त्रोग लेटा आंक आआन की यहाज्प तीन स्तुड़ईटाई में एंटर की और उसे बाख पुगरां की प्रूँँँँँँँँँँँँँँatorium.com. अप देटा में आप रइट से रइट किया था उसको खड करो, और उसको फाल अपन करने के जस्बात लिखो, और आप रइट की जगे किया लिख तो आप लीट, आप लीट देटा एसके अंदा दीट करेगा, जो एक ब्लोक है उसका साईज अगा स्ट्रक स्चुडन्त के अप और तो साईज अप लिख अप शाईज अप लीट यहा जितना देटा अपने फी ण्तान की अप दीट अप रइट कर पावगे, यहा मैं लिख देटां स्टूडन्त, दीटेल्स जे थी के अप पूडना डेटा एस वीरेज़al me reed ho jaayega to उसको प्रंत कर आनाप लिट तो तेटाम ने पिछले प्रुग्रान के तु फायल में स्थोर दिया था वो अतमेंटिक लिए प्रेंट हो जाए में जैसा की हर बार हो रहा है, तो हम ने कंपाल और एख्जिक्योट किया, रिजाल ताप के सामने, आपको समज में है अगर की पहली बाद तो बायरी फायल कैसे प्रोससस करतना है, तो उसके लिए आपको मोड के बाद भी अटेच करना है, टिके हमने आर भी और ड़ूब भी उस किया, अगर आप एगी प्रुग्राम को बहुत बहुत बार एख्जिक्योट करतना है, खॉरी video series को फलो करें आपके अपना se language का सबजक्त है. आपको समच में आपको आपको सवोज़ेशन भाबगा आपको सवज्विया है अपको सजच्विया है, ताप मुझे कमिनिकेट करते मेरे बीटब्रेख से सकते हैं, Thank you for watching this video.