This blog is under construction

Friday, 27 April 2012

fputc example in C

Header file:
    stdio.h

Synopsis:
     int fputc(int c, FILE *stream);

Description:
     It writes the character 'c' on the given stream.  Returns the written character on success.  Otherwise, EOF is returned.


fputc function C example:


  #include<stdio.h>
  int main() {
        char ch;
        FILE *fp;
        fp = fopen("file.txt", "w");
        while ((ch = getchar()) != EOF)
                fputc(ch, fp);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
  Hello world
  jp@jp-VirtualBox:~/cpgms/exp$ cat file.txt
  Hello world



1 comment:

  1. I found best article.thank you for sharing useful info.
    visit
    web programming tutorial
    welookups

    ReplyDelete