Tuesday, December 6, 2011

Write a C Program to create a File and write some text line and read thisfile

#include <stdio.h>
#include <conio.h>
void main()
{
 FILE * fp;
 char s[800];
 clrscr();
 fp=fopen ("Salary.txt","w");
 if(fp==NULL)
 {
  puts("\nFile creating unsuccessful");
  exit(1);
 }
 printf("\nEnter a few line:\n ");
 while(strlen(gets(s))>0)
 {
  fputs(s,fp);
  fputs("\n",fp);
 }
 fp=fopen("NONAME00.C","r");
 if(fgetc(fp)==NULL)
 {
  return(EOF);
 }
 while(fgets(s,79,fp)!=NULL)
 {
  printf("%s",s);
 }
 fclose(fp);
 getch();
}

No comments:

Post a Comment