1. 程式人生 > >檔案系統寫操作

檔案系統寫操作

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


#define  STD_FILE_INPUT		0
#define  STD_FILE_OUTPUT	1
#define  STD_FILE_ERROR		2

int main(int argc, char* argv[]){

	char data[]  = "Here is a data\n";
	int count = sizeof(data) / sizeof (data[0]);
	printf("count = %d\n", count);
	int rc = write( STD_FILE_OUTPUT , data, count );

	if(rc != count){
		char err[] = "write failed\n";
		int err_n = sizeof(err) / sizeof (err[0]);

		rc = write( STD_FILE_ERROR, err, err_n );
		printf("err n = %d\n", rc);
	}

	printf("Write result :  n = %d\n", rc);

	return 0;
}