Anand Hariharan
7/22/2011 2:24:00 PM
On Jul 21, 10:29 pm, Malcolm McLean <malcolm.mcle...@btinternet.com>
wrote:
> On Jul 21, 10:35 pm, happytoday <ehabaziz2...@gmail.com> wrote:> It was required to remove empty lines using C program . Either to be
> > run like :
>
> > ./nnoemptylines < textfile
>
> > or accept location of the file as a full path from the user dialog to
> > accept .
>
> The spec is almost impossible.
>
FWIW, while the point you make below is valid, I doubt if that is what
the OP intended.
> ./noemptylines < textfile redirects textfile to stdin. So if the
> program is invoked thusly, it needs to read in lines from stdin, check
> if they are non-blank, and then echo them to stdout. So far so good.
> The problem is that
> ./noemptyfiles
>
> should set up a dialogue with the user. So you want to print something
> like
> "Hello user, please enter the name of the file from which ypu wish to
> remove blanks"
> The user enters
> textfile
> "Thank you, do you wish to overwrite the file?"
>
> etc
>
> The problem is that there's no easy way to know whether stdin is
> directed from a file or coming from a keyboard. That's deliberate. We
> don't generally want programs making this distinction. I'm sure that
> on your particular system there will besome operating call, probably
> poorly documented, which you can make. But it's inappropriate and bad
> practice to use it for a ultility program like a deblanker.
>
POSIX provides a 'isatty()' that allows programs to make such a
distinction.
- Anand