pTutorial

New way to learn Programming

Objective C example

In this c example we will focus on file handling on c first of all we will learn how to write a sentence in a file by the c program.

Write file C example


#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
   char ch[1500];
   FILE *ft;
   ft=fopen("ptutorial.txt","w");
   if(ft==NULL){
      printf("Exception occure");
      exit(1);
   }
   printf("Enter any thing to write on file:\n");
   gets(ch);
   fprintf(ft,"%s",ch);
   fclose(ft);

}

Download file write c example

Output of program

Objective C example

Explanation

After execution of that program, you can see the text file named ptutorial.txt on the same location where the c program store. You can see the text by clinking this file.

In the above program, a file is open in write mode using "w" that means if the file is exist, its content loose and overwritten the current content and if its not exist it will created. fprintf() function is used to store the content into the file.


QUOTES OF THE DAY

The ballot is stronger than bullet.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER