Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Thursday, May 4, 2017

File Handling in C(Explained in every mode)


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ch[5000],che;
FILE *ptr; // a file pointer
ptr=fopen("abc.txt","a+"); // open in a+ mode (append)

//while((ch=getchar())!=EOF)
//fputc(ch,ptr); // by fputc function

printf("%s\n",fgets(ch,200,ptr));
gets(ch);

fputs(ch,ptr);

fclose(ptr);

ptr=fopen("abc.txt","r"); // open only by read mode so that it start to read from starting
//printf("%s\n",fgets(ch,200,ptr));
while((che=fgetc(ptr))!=EOF)
printf("%c",che);
fclose(ptr);
getch();
}

0 Comments:

Post a Comment

Stats