C Program to create a File & write Data in it1 min read

This is a file tutorial where we will write a C program to create a file and write into it. Before that, you may go through the following C topics.

Explanation: The program is based on the file system in C. The program opens the file system in writing mode, hence the “w”. If the file is not present with the name provided then the program will create a file on the same directory.

The program will check if the file is Null or not. If not then, it will ask the user to enter data which later will be inserted into the file. Let us go through the program.

Program to write into a file in C

Output:

write a file in C

After successful execution of the program, a file named “test.txt” will be created (if not already created) in the same directory where you have stored the source code file. Open that file and you will see the data that you wrote on the program will be present there in the following way.

This is simple2code.com


MORE

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More

Inverted Half Pyramid Pattern of Alphabets in C

In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More