Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Create Files:

Creating files in C language involves using file handling functions provided by the standard I/O library. Here's a simple explanation with an example of creating a file:

#include <stdio.h>

int main() {
FILE *filePointer; // Declare a file pointer

// Open file in write mode (creates the file if it doesn't exist)
filePointer = fopen("example.txt", "w");

// Check if file was successfully opened
if (filePointer == NULL) {
printf("Unable to create file.\n");
return 1; // Exit program with error
}

// Write content to the file
fprintf(filePointer, "This is an example file created using C language.");

// Close the file
fclose(filePointer);

printf("File created successfully.\n");

return 0;
}

In this example

When you run this program, it will create a file named "example.txt" in the current directory (where the executable is located) and write the specified content to it.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java