0

calLinux/UNIX で 1 か月だけ表示するのではなく、" " 3 か月 (1 か月前と 1 か月後) を並べて表示するようにこのプログラムを作成する必要があります。system(customCommand)" " を 3 回使用することで、3 つのカレンダーを表示できるようになりました。しかし、それは並んでいません。

次のシステム コールを使用するためのヒントを得ました。

close(..) pipe(..) dup2(..) read(..) and write(..)

私の質問は、何から始めるべきですか?子プロセスを作成し、それをキャッチする必要がありますpipe(..)か?

3 つのカレンダーを並べて表示するにはどうすればよいですか。

元。

    February 2009          March 2009             April 2009
 S  M Tu  W Th  F  S    S  M Tu  W Th  F  S    S  M Tu  W Th  F  S
 1  2  3  4  5  6  7    1  2  3  4  5  6  7             1  2  3  4
 8  9 10 11 12 13 14    8  9 10 11 12 13 14    5  6  7  8  9 10 11
15 16 17 18 19 20 21   15 16 17 18 19 20 21   12 13 14 15 16 17 18
22 23 24 25 26 27 28   22 23 24 25 26 27 28   19 20 21 22 23 24 25
                       29 30 31               26 27 28 29 30
4

6 に答える 6

6

if "cal -3" doesn't work, just use paste :)

$ TERM=linux setterm -regtabs 24
$ paste <(cal 2 2009) <(cal 3 2009) <(cal 4 2009)
    febbraio 2009            marzo 2009              aprile 2009
do lu ma me gi ve sa    do lu ma me gi ve sa    do lu ma me gi ve sa
 1  2  3  4  5  6  7     1  2  3  4  5  6  7              1  2  3  4
 8  9 10 11 12 13 14     8  9 10 11 12 13 14     5  6  7  8  9 10 11
15 16 17 18 19 20 21    15 16 17 18 19 20 21    12 13 14 15 16 17 18
22 23 24 25 26 27 28    22 23 24 25 26 27 28    19 20 21 22 23 24 25
                        29 30 31                26 27 28 29 30

$   

(setterm ignores -regtabs unless TERM=linux or TERM=con.)

于 2009-03-31T19:45:35.387 に答える
6

「cal -3」を使用する代わりに自分で書きたいと仮定すると、私は何をしますか(疑似コードで):

popen three calls to "cal" with the appropriate args

while (at least one of the three pipes hasn't hit EOF yet)
{
  read a line from the first if it isn't at EOF
  pad the results out to a width W, print it
  read a line from the second if it isn't at EOF
  pad the results out to a width W, print it
  read a line from the third if it isn't at EOF
  print it
  print "\n"
}

pclose all three.
于 2009-03-31T19:38:36.730 に答える
3

ただする

cal -3 
于 2009-03-31T19:32:11.613 に答える
1

これは機能しませんか?

cal -3

于 2009-03-31T19:33:27.697 に答える
1

わかりました、どうcal -3ですか?

cal -3 12 2120前後に 1 つずつ、特別な月と年にします。

于 2009-03-31T19:33:28.427 に答える
0

これに使用するアプローチは、出力をキャプチャして行に分割し、行を並べて出力することです。C ではなく Perl でやった方がいいと思います。

または、cal がある場合は cal -3 を使用します。

于 2009-03-31T19:32:49.287 に答える