从文本文件

时间:2016-04-20 17:56:53

标签: c input dev-c++

我需要创建一个函数,它将输入.txt文件作为输入,然后继续 在做一堆操作的同时处理每个角色。

这就是函数的声明。

int ProcessInput(FILE *in);

问题是我不想从键盘输入,而是从前面提到的.txt文件中获取输入。 我正在开发Dev C ++。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

#include <stdio.h>

int main(int argc, char** argv)
{
  if (2 > argc)
  {
    printf("Please enter a file name on the command line\n");
    return 0;
  }
  FILE* in = fopen(argv[1], "r");
  if (!in)
  {
    printf("Unable to open the specified file\n");
    return 0;
  }
  ProcessInput(in);
  fclose(in);
  return 0;
}
相关问题