用C编写简单文件的Unix编程

时间:2011-06-05 09:59:59

标签: c unix file-io

我必须编写一个简单的程序,将16个字节的数据输出到0和48位的文件,并提出了这个程序:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    int f = create("test.tmp",774);
    if(f>0)
    {
        write(f,"DEPARTMENT OF CS",16);
        lseek(f,48,SEEK_SET);
        write(f,"DEPARTMENT OF IS",16);
    }
    return 0;
}

这有什么问题?它告诉我何时使用cc 7a.sh -ll编译:

  

未定义以引用'create'

2 个答案:

答案 0 :(得分:6)

没有名为create

的功能

它名为creat

答案 1 :(得分:1)

#include <stdio.h>

int main ()
{
  FILE * pFile;
  pFile = fopen ( "example.txt" , "w" );
  fputs ( "This is an apple." , pFile );
  fseek ( pFile , 9 , SEEK_SET );
  fputs ( " sam" , pFile );
  fclose ( pFile );
  return 0;
}

通过http://www.cplusplus.com/reference/clibrary/cstdio/fseek/