簡體   English   中英

Unix 編程在 C 中用於簡單文件

[英]Unix programming in C for simple files

我必須編寫一個簡單的程序到 output 16 字節的數據到文件的第 0 和第 48 position 並提出了這個程序:

#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的 function

它被命名為創作

#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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM