how this c code works?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgayathri2412
    New Member
    • Oct 2012
    • 8

    how this c code works?

    I want to know how this code works,will you please explain me?
    Code:
    <#include<stdio.h>
    main()
    {
      int c;
      printf("Enter character(CONTROL-Z to end):");
      c=getchar();
      if(c!=EOF)
      printf("End of file not encountered!");
    }
    Last edited by Frinavale; Oct 25 '12, 01:46 PM. Reason: Formatted code and corrected a code tag.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The printf method prints the provided string onto the standard output (typically the screen).

    The getchar() method retrieves a character from the standard input (typically your keyboard).

    The EOF stands for End Of File.

    So this program prints "Enter character(CONTR OL-Z to end):" on the screen.

    It then retrieves a character entered by the user.

    If the character entered by the user is Not equal to EOF, it prints "End of file not encountered!" on the screen.

    Please try running the application to see the output.

    Use a debugger to step through the application to understand what is happening.

    And use resources, like Google, to research the topic before asking your question.



    -Frinny

    Comment

    Working...