codechef IDE OUTPUT

I wanted to take string input from user till user enters EOF.

code:

                                                                                                                                   #include <stdio.h>

 int main(void)
   {
// your code goes here
int ch;
//char c;
ch=getchar();
char s[100];
int count=0;
while(ch!=EOF)
{
    
    s[count]=ch;
    count+=1;
    ch=getchar();
    printf("asciivalue=%d %c\n",ch,ch);
}
printf("hello");
printf("%d",count);

return 0;

}

Input

 hello
 sgf

Outpt

 asciivalue=101 e
 asciivalue=108 l
 asciivalue=108 l
 asciivalue=111 o
 asciivalue=10 

 asciivalue=115 s
 asciivalue=103 g
 asciivalue=102 f
 asciivalue=10 

 asciivalue=10 

 asciivalue=10 

 asciivalue=-1 

I dont understand why newline character is displayed 2 times extra at the end(10) before EOF(-1).

Also, one more doubt why hello and count is not displayed?? plz explain thanks

Hello,
I tested your code and used the same input (‘hello’ and ‘sfg’) Here is my output on Windows 7

inputs:
hello
sfg


output:
hello
asciivalue = 101 e
asciivalue = 108 l
asciivalue = 108 l
asciivalue = 111 o
asciivalue = 10

sgf
asciivalue = 115 s
asciivalue = 103 g
asciivalue = 102 f
asciivalue = 10

^Z
asciivalue = -1  
hello10


Your code is working fine. Better way to accomplish what your are trying is to use either ‘\0’ or ‘\n’ instead of EOF.
In my case hello and count got printed as well.

In c string is always ended by null character (’\0’) ascii value=0,then its not showing