2015-06-19 89 views
-6

我是Ubuntu的新手,我正在学习关于在C编程中学习的FILE。我写了我的代码,但是我不能运行它们,因为它想要我另一个库。那么,哪个库包含FILE?我只使用#include <stdio.h>,但在ubuntu中有点不同。我需要一个库名

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


int main() 
{ 
    FILE *ptrFILE; 
    if(ptrFILE = fopen("Test.txt","w")==NULL) 
    { 
     printf("The file couldn't opened\n"); 
    } 
    else 
    { 
    int i; 
    for(i=1; i<=20; i++) 
    { 
      fprintf(fptrFILE,"%d\n", i*5); 
    } 
    fclose(ptrFILE); 
    return 0; 
} 
+3

你包括? –

+1

你使用什么编译器?你是否正确安装? – usr2564301

+0

您的代码是否成功编译,但无法链接? – donjuedo

回答

2

FILE数据是通<stdio.h>限定的不透明struct和实施是在C standard library(它是通过隐含gcc连接 - 或clang - 在Ubuntu)。

因此,只要在你的终端运行

gcc -Wall -g aprog.c -o abinary 

然后在同一终端

注运行./abinary编译源文件aprog.c-Wall询问gcc编译器几乎所有的警告(添加-Wextra到得到更多)和-g要求调试信息(以便能够使用gdb调试器或valgrind,稍后)。

不要忘记安装build-essentiallibc6-dev Ubuntu的软件包