This blog is under construction

Friday 27 April 2012

putc example in C

Header file:
    stdio.h

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

Description:
     It writes the character c into the given stream.  It evaluates the given stream more than once, if it is a macro.  Returns integer value(ascii) of the written character on success or EOF on failure.


putc function C example:


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



  Output:
  jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
  Hello world
  This is putc example program in C

  jp@jp-VirtualBox:~/cpgms/exp$ cat input.txt
  Hello world
  This is putc example program in C



No comments:

Post a Comment