Tuesday, 27 August 2013

c program to read the input and place into to a file

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int main()
{
    FILE *fp;
    char ch;
   
    if(!(fp=fopen("sample.txt","w")))
    {
                                    printf("error in opening the file");
                                    getch();
                                    exit (1);
                                    }
                                   
                                    while((ch=getchar())!=EOF)
                                    {
                                                              putc(ch,fp);
                                                              }
                                                             
                                                              fclose(fp);
                                                             
                                                              getch();
                                                              return 0;
                                                              }

No comments:

Post a Comment