
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - write
[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
write
Usage
#include <io.h>
int write(int fd,void *buffer,size_t length);
Description
Write length bytes from buffer to the file specified by the file
descriptor fd. This is a binary-only operation and is not buffered.
Implemented as a direct DOS call.
Example
#include <io.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
main()
{
unsigned int fd;
char *buffer = "Write this data to file";
unsigned int count;
int nwritten;
count = strlen(buffer);
fd = open("file.dat",O_WRONLY);
if(fd == -1)
{
fputs("Unable to open file",stdout);
return;
}
nwritten = write(fd,buffer,count);
printf("\nWRITE:\n%u bytes written to file\n",nwritten);
close(fd);
}
Return Value
write returns the number of actual bytes written or a -1 if an error
occurred and errno is set.
Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson