File MAnagement in dsa
File handling is what known as file handling simple you are handling files that 's it you are creating files. You are supposed to handle these files.. files are of two types, text and binary text means having note Txt extension that those files and binary dot bin dot pin are simple plain text files like notepad or wordpad or document you know microsoft word.. This is just an introductory part on files in c right and to handle these files. You will need a pointer that is file pointer. these are main operations on files. Many more operations are there one one by one will discuss all the operations with proper programs.. are supposed to close that file right.. it is loaded into RAM, which is a volatile memory, and if you want to store the input/output data permanently, then you can store it on a hard disk using a file. This data type is defined in stdio.h, and you can use it directly in your program by simply including this header file. The implementation of file handling depends on the operating system and machine, but we will have a pointer. In Python, we use the fopen() function to open a file. This function returns the address of the file and the address is stored in a file pointer variable (in short, fp). It's important to understand that you don't need to go through the deep process of opening a file. You just need to write a simple line to open a file with:fopen(filename, mode) It's essential to close the file once you've finished working with it using:fclose(fp) Remember, if you open a file, you can do anything with that file. If you want to read something from this file, you need a function like fprintf(). Once you close a file, it's freed and can be used by any other code or pointer. These are full-length smoke tests, so they will cover the entire syllabus. Parents can take this test for free, and it will be a live test. If you take it live, you will get your All India ranking. The academy is also going to conduct a scholarship test for GATE on 2nd January at 11 am. The process of creating a file using f open function can simply be described as opening a file. We have previously discussed the actual process of creating an Excel file. Now, let's learn how to create this file type of pointer. This pointer (fp) contains the address of this buffer, and we can coordinate with this file. There are three functions available to write something: fputc(c, output_stream): - can be used to write a single character to the output stream. fputs(s, output_stream): - used to write a string to the output stream. fprintf(file_pointer, format_specifier, ...): - to write formatted output to a stream.We can use fputc to write a complete string by writing the characters one by one in a loop:for (int i = 0; i strlen(str); i++) { fputc(str[i], output_stream);}For writing to a file, instead of output_stream, we will use the file pointer, which is fp in this case. The format specifier for writing a number is "%d" and for writing a string is "%s".fprintf(fp,"%d %s", a, str);Here, "a" is the integer variable and "str" is a character array or string. To pass the string to fprintf, we use the base address of the character array using the "&" operator. Using the fopen function, we are going to open the file. We will pass the name, in this case, "", in double quotes. We will save the address returned by the fopen function in file pointer fp. Since I don't have an abc file in my current directory, let's assume we have a C program folder on our desktop. We will open the file in append mode, which we will discuss later. Now, let's use the fprintf function to write some data into the file. Here, I am taking another variable a, which is equal to 10. We will write the number and the string or maybe we can take a character. Currently, we have Jenny's lectures. In the next video, we will see how to read something from a file. We will discuss the three functions, namely fputc, fgets, and fprintf, and the modes of opening file. I hope you understand how to write something to a file in write mode using the fopen and fprintf functions.
Geschreven voor
- Instelling
- MAKAUT University
- Vak
- Data Structure and Algorithm
Documentinformatie
- Geüpload op
- 19 maart 2023
- Aantal pagina's
- 13
- Geschreven in
- 2022/2023
- Type
- College aantekeningen
- Docent(en)
- Nil
- Bevat
- Alle colleges
Onderwerpen
-
file management