2014年1月1日水曜日

開発環境

C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)のⅢ部(高度なプログラミング概念)の20章(移植性の問題)、20.6(ファイル名問題)、設問20-2.を解いてみる。

その他参考書籍

設問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 コメント:

コメントを投稿