Agenda

switch cases, ternary operators.

Notes

  • printf before infinite loop does n’t seem to be executed

    • Solution

    • The way printf() works is like this: it stores the value to be printed in a buffer or a reserve. It only displays it to the terminal(stdout) when either there is a /n (newline) in the printf() or if the program terminates. Since neither happens here, the output of the first printf (which is before the infinite loop) is not displayed. Read this.

$ \ $

  • tail -10 t.c > t.c returns an empty file

    • Solution

      The > sets stdout to t.c in the command: tail -100 t.c > t.c .What that signifies is that t.c is created anew and made ready for what tail will return. Thus, even before the tail -100 t.c part is executed, t.c is emptied, resulting in the final empty file.

    • Read this and this

$ \ $

  • wc -l file returns filename, though wc -l < file doesn’t

    • Solution

      In the second case, when stdin is set to file1, wc no longer knows its using file1 as input, it just works with stdin. To try this out, you can just type: $ wc -l This is allow you to enter text and when you hit ctrl D, you get the number of lines you entered (and without the file name).

$ \ $

  • Defining functions with variable arguments in c