ソフトウェア設計及び演習2017

サンプルプログラム::ファイル識別子

 # include <stdio.h>
 # include <fcntl.h>
 # include <string.h>
 
 # define SINPUT 0
 # define SOUTPUT 1
 # define SERROR 2
   
 int main()
 {
    char *message;
    int newid;
 
    newid = open("aFile.txt",O_CREAT|O_WRONLY, 0644);
    printf("New File Descriptor = %d\n", newid);
    message = "this is a text for aFile.txt\n";
    write(newid, message, strlen(message));
    close(newid);
 
    message = "this is standard-output text\n";
    write(SOUTPUT, message, strlen(message));
 
    message = "this is standard-error text\n";
    write(SERROR, message, strlen(message));
 
    return 0;
 }


最終更新日:2017/04/03 09:14:15