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