Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Which of the following is the symbol used to redirect standard input? (programming in C)?

C Programming Question

Which of the following is the symbol used to redirect standard input?

Choices are & and <.

Please explain with an example.

3 Answers

Relevance
  • Anonymous
    10 years ago
    Favorite Answer

    Its <

    For example if you have a program, you can redirect standard input by doing:

    program.exe < inputfile.txt

    and the program will read input from inputfile.txt rather than from a keyboard (aka 'standard input')

  • 10 years ago

    It's <

    myprogram.exe < afile.txt

    Rather than taking it's input from the keyboard,

    myprogram.exe will get the content of the afile.txt

    sent as input.

    This is part of the operating-system, not C itself.

    (In Unix/Linux & puts the program in the background

    for execution, so the shell can be used for other programs,)

  • Anonymous
    10 years ago

    Neither. You can re-direct stdin using freopen.

    EDIT: If you're too stupid to realise that whatever shell you use has nothing to do with C, then you're either confused or mentally retarded. In C, & is the bit-wise and operator, and < is the relational less-than operator. Neither are used for redirecting stdin. If you want to redirect stdin within a C program, you can do so with freopen, in a similar manner as shown below:

    #include <stdio.h>

    /* ... */

    if(!freopen("file", "r", stdin))

       /* Handle Error */

    This will achieve a similar result as executing a program from a shell, like so: "./program < file", except that it's done within C itself, thus being relevant to your poorly worded question.

    I recommend you get a book on either UNIX or C. Whatever you think you're trying to learn.

Still have questions? Get your answers by asking now.