English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Using realloc() in C

This functionfopen()Open the file pointed to by the pointer and read or write to the file. In write mode, use "w", in read mode, use "r".

If a file exists in the directory, it is treated as a new empty file and its content is overwritten with new data.

This isfopen()C language syntax,

FILE *fopen(const char *filename, const char *access_mode)

Here,

filename-The name of the file to be opened.

acess_mode-Access modes to files, such as read or write modes.

This isfopen()C language example,

Assuming we have a file named "one.txt" containing the following content.

This is demo text!
This is demo text!
This is demo text!

Now, let's look at an example.

Example

#include <stdio.h>
#include<conio.h>
void main () {
   FILE *f;
   int len;
   f = fopen("one.txt", "r");
   if(f == NULL) {
      perror("Error opening file");
      return(-1;
   }
   fseek(f, 0, SEEK_END);
   len = ftell(f);
   fclose(f);
   printf("Size of file: %d bytes", len);
   getch();
}

Output result

Size of file: 78 bytes

In the above program, the file type pointer variable is declared as f and is used tofopen()The function opens a file named "one.txt".

FILE *f;
int len;
f = fopen("one.txt", "r");