1

Firstly, I'm REALLY new to programming. I've just started my first programming class two weeks ago, and I apologize if I sound newbish.

My professor wants me to implement a "press any key to continue..." thing in my program. Basically when I run a program, he wants one line to come up [like printf("jfdskaljlfja");] then what would come up is "press any key to continue," before the next line runs. he told us that the DOS equivalent is system("pause"), but he wants us to do it linux. This is what my code looks like:

    #include <stdio.h>
    int main()
    { 
         printf("This is the first line of this program);
         system("pause");
         printf("This is the second line);
    }

Except he wants us to do this in Linux, so system("pause") won't work in this case. Is there a way to have it do exactly what pause does, but in linux terms?

again, sorry if i sound newbish. thank you so much!

Also, he doesn't really care if the code is efficient or anything, as long as it runs. Again, i'm really new to programming, so the simplest answer would be much appreciated :)

  • 5
    Welcome to Stack Overflow. Please read the [About] page soon. Also, always submit compilable code. It is clear that the code you show has never been compiled; there are two missing close quotes, and two missing newline `\n` escape sequences — at minimum. – Jonathan Leffler Oct 29 '13 at 03:40
  • Also, post up what you've already tried. Giving you the answer isn't going to help you learn – tangrs Oct 29 '13 at 03:40
  • This is the code my professor gave me (unfortunately), he just sent out an email saying to add those. Thanks! – user2930466 Oct 29 '13 at 03:42
  • I am now confused. He basically told us to research the command, and I've come up with nothing. I've read things about a read command and functions, but we haven't covered that yet. – user2930466 Oct 29 '13 at 03:43
  • 2
    The question's addressed in here, along with a lot of other stuff worth learning: http://www.faqs.org/faqs/unix-faq/programmer/faq/ – Tony Delroy Oct 29 '13 at 04:19
  • Read [Advanced Linux Programming](http://advancedlinuxprogramming.com/) and learn about [poll(2)](http://man7.org/linux/man-pages/man2/poll.2.html), [nanosleep(2)](http://man7.org/linux/man-pages/man2/nanosleep.2.html), and many many other [system calls](http://en.wikipedia.org/wiki/System_call) – Basile Starynkevitch Oct 29 '13 at 07:26

1 Answers1

2

You can do the same thing on linux with

system("stty -icanon -echo; dd if=/dev/tty of=/dev/null bs=1 count=1 2>/dev/null; stty icanon echo");

or you can put that string in a shell script called pause and continue to run system("pause");

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226