2007-11-01から1ヶ月間の記事一覧

1-10

これ、バックスペースの入力ってどうやってテストするんだろと思ったけど、 echoで出力した文字列をパイプでつないでやって解決。 #include <stdio.h> /* * タブを\tに、バックスペースを\bに、バックスラッシュを\\に置き換え、 * 入力を出力に複写する **/ main(){ </stdio.h>…

1-9

OKOK #include <stdio.h> /* * 2つ以上の空白を1つの空白に置き換えながら * 入力を出力に複写する **/ main(){ int c,beforec; while((c = getchar() ) != EOF){ if (c != ' ' ){ if(beforec == ' '){ putchar(beforec); } putchar(c); } beforec = c; } exit(0); </stdio.h>…

1-8

まだなんとか。 #include <stdio.h> /* * 空白、タブ、改行を数えるプログラム **/ main(){ int c,spaceCounts,tabCounts,returnCounts; spaceCounts = 0; tabCounts = 0; returnCounts = 0; while((c = getchar() ) != EOF){ if (c == ' '){ spaceCounts++; } if (c </stdio.h>…

1-7

コレは簡単。 #include <stdio.h> /* * EOF の値を印字するプログラム **/ main(){ printf("%d",EOF); } [ERROR:1]% ./1-7 -1%</stdio.h>

1-6

難しい。。。。 #include <stdio.h> /* * getchar() != EOF が0か1しかないことを確認 **/ main(){ int c; c = 1; while(c){ c = (getchar() != EOF); printf("%d",c); } } [ERROR:1]% echo '1234' | ./1-6 111110% 5回1がでてるのは末尾に\nがついているから?全</stdio.h>…

1-6

難しいなぁ。。。。

禁煙継続中(8/19~)

もう4ヶ月もまったくすってない。 流石にもう吸いたい気もしないなぁ。

1-5

for文を使ってみる [5638]% gcc 1-5.c -o 1-5 -Wall 1-5.c:6: warning: return type defaults to `int' 1-5.c: In function `main': 1-5.c:17: warning: control reaches end of non-void function [5639]% cat 1-5.c | c2utf #include <stdio.h> /* * fahr=300,280・</stdio.h>…

1-4

ちょっとした復習。 [ERROR:15]% cat 1-4.c |c2utf && ./1-4 #include <stdio.h> /* * celsius=0,20,・・・300に対して、摂氏-華氏温度対応表を作成 **/ main(){ float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; celsius = lower; </stdio.h>…

1-3

printfの使い方。man printf。 [5623]% cat 1-3.c |c2utf #include <stdio.h> /* * fahr=0,20,・・・300に対して、華氏-摂氏温度対応表を作成 **/ main(){ float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; fahr = lower; printf("%</stdio.h>…

コンパイルして実行をvimから1キーで実行

$HOME/.vimrcに以下の行を追加 map <F5> :w<CR>:!gcc % \| ./a.outF5キーを押すと実行してくれます。なんかデフォルトでうまくやる方法がある気がするんだけど、 とりあえずいいこの設定で快適なのでOKです。</cr></f5>

1-2

printfのなかで\xを使ってみなさいという演習。 [ERROR:13]% cat 1-2.c [/home/utadaq/work/kandr] #include <stdio.h> main(){ printf("hello, world\x",0x0c); } [5418]% gcc 1-2.c -o 1-2 [/home/utadaq/work/kandr] 1-2.c:4:9: \x used with no following hex dig</stdio.h>…

1-1

hello worldの演習。 [5414]% cat 1-1.c [/home/utadaq/work/kandr] #include <stdio.h> main(){ printf("hello, world\n"); } [ERROR:127]% ./1.1 [/home/utadaq/work/kandr] hello, world</stdio.h>

はじめに

K&R C

超有名な、K&RのC言語の本を買ったから、こつこつと読み進めて行こうと思います。 演習問題のメモをぽつぽつと書いていこうかと。

なるほど

ニコニコのコメントが、ばらばらと横に流れながら、 あるタイミングでみんなの気持ちがひとつになったような 弾幕が流れるのは とてもきれいだなぁ。