開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang (コンパイラ)
C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)のⅢ部(高度なプログラミング概念)の20章(移植性の問題)、20.6(ファイル名問題)、設問20-2.を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
設問20-2.
\r、\n、\tがそれぞれ復帰、改行、タブ文字と、エスケープ文字として解釈されるから。
修正。
コード
sample.c
#include <stdio.h> #include <stdlib.h> FILE *in_file; #ifndef __MSDOS__ const char NAME[] = "/root/new/table"; #else const char NAME[] = "\\root\\new\\table"; #endif /* __MSDOS__ */ int main(int argc, char *argv[]) { in_file = fopen(NAME, "r"); if (in_file == NULL){ fprintf(stderr, "%s: file not found\n", NAME); exit (8); } return (0); }
入出力結果(Terminal)
$ cc -g -o sample sample.c $ ./sample /root/new/table: file not found $
0 コメント:
コメントを投稿