コマンドラインにリストされたすべてのファイルの内容を画面に順番に表示するプログラムを作成しました。
ただし、ターミナルで実行すると、実際に「フィード」しようとするファイルを開くことができません。
どうすればそれを機能させることができるか知っている人はいますか?
これは、Mac のターミナルに入力している内容の例です。
"John_Smith-MacBook:Desktop smith_j$ "/Users/smith_j/Desktop/Question 3-28-13 5.10 PM/usr/local/bin/Question" helloworld.txt
Could not open file helloworld.txt for input"
ターミナルを使用したのはこれが初めてなので、答えが非常に簡単な場合はご容赦ください。
これが私のコードです:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int byte;
FILE * source;
int filect;
if (argc == 1)
{
printf("Usage: %s filename[s]\n", argv[0]);
exit(EXIT_FAILURE);
}
for (filect = 1; filect < argc; filect++)
{
if ((source = fopen(argv[filect], "r")) == NULL)
{
printf("Could not open file %s for input\n", argv[filect]);
continue;
}
while ((byte = getc(source)) != EOF)
{
putchar(byte);
}
if (fclose(source) != 0)
printf("Could not close file %s\n", argv[1]);
}
return 0;
}