-1

On executing this snippet whatever input I give,the console doesn't stop getting an input,is there any possible way to terminate this snippet with an input to stdin.

#include<stdio.h>
 void main()
{
char s1[100];
scanf("%[^EOF]s",s1);
   or
scanf("[^\0]s",s1);
printf("%s",s1);
}
Abdul Khader
  • 79
  • 1
  • 7
  • 2
    Possible duplicate of [How do you read scanf until EOF in C?](https://stackoverflow.com/questions/3764014/how-do-you-read-scanf-until-eof-in-c) – Rivasa Oct 07 '17 at 15:57
  • Use just `"%99s"`? The `scanf` function will stop reading on whitespace like for example a newline. If you want to read a whole line, then perhaps use [`fgets`](http://en.cppreference.com/w/c/io/fgets) instead? – Some programmer dude Oct 07 '17 at 15:57
  • @Annabelle sorry that question doesn't have an answer – Abdul Khader Oct 12 '17 at 09:14

1 Answers1

0
scanf("%[^EOF]", s1);

It means that any character will be considered as part of the string except EOF. To terminate the string you should input EOF character which is Ctrl+D on Unix/Linux systems.

Fractal
  • 816
  • 5
  • 15
  • Sorry that didn't answered my question.I have tried Ctrl+D which is also as an input and gets printed on console like this ^D. – Abdul Khader Oct 08 '17 at 08:18