这里有什么缺少的头文件(C代码)?

时间:2012-02-09 20:27:33

标签: c code-analysis

我正在阅读C教程,#include之后缺少某些东西:

/***  reads in n integers from a file,
      then prints the values to another file as type float  ***/
#include        /***  for file manipulation functions  ***/
#include       /***  for malloc()  ***/

main()
{
  int i, n, *x;
  char file_name[FILENAME_MAX];
  FILE *fp;

  printf("file name for input: "); scanf("%s", file_name);
  fp = fopen(file_name, "r");
  if (fp == NULL)
    {
      printf("error: could not open file %s\n", file_name);
      exit(-1);
    }

  fscanf(fp, "%d", &n);
  x = (int *) malloc(n * sizeof(int));

缺少什么?

2 个答案:

答案 0 :(得分:3)

#include <stdio.h>
#include <stdlib.h>

你不能只搜索吗?

答案 1 :(得分:3)

#include <stdio.h> // for file manipulation
#include <stdlib.h> // for malloc()

这很容易谷歌。