Using file handling, create a file, insert some characters and count them

Advertisement
Q. Using file handling, create a file, insert some characters and count them
ANS. #include<stdio.h>
#include<conio.h>

void main()
{
 char ch;
 int count=0;
 FILE *fptr;
 clrscr();
 fptr=fopen("text.txt","w");
 if(fptr==NULL)
 {
  printf("File can't be created\a");
  getch();
  exit(0);
 }
 printf("Enter some text and press enter key:\n");
 while((ch=getche())!='\r')
 {
  fputc(ch,fptr);
 }
 fclose(fptr);
 fptr=fopen("text.txt","r");
 printf("\nContents of the File is:");
 while((ch=fgetc(fptr))!=EOF)
 {
  count++;
  printf("%c",ch);
 }
 fclose(fptr);
 printf("\nThe number of characters present in file is: %d",count);
 getch();

}

Note:- if Solved Assignment will not be downloaded after the payment, checkout your email address there is a email form instamojo and there will be the option of DOWNLOAD FILES please click on that your assignment will be downloaded instantly and please open file in PDF reader.


11AM TO 6PM CALL US +919811854308 Contact us:- ignouassignmentguru@gmail.com
Previous
Next Post »
Thanks for your comment