Re: write



In comp.os.linux.development.system, Bill Cunningham wrote:

To correct your program...

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

int main (void) {
int file;
char buf[]="hello world\n";
size_t c;
/*
c = 20000;
*/

if ((file = open("my_file",O_WRONLY | O_CREAT | O_TRUNC,0644)) != -1)
{
c = sizeof(buf);
write(file,buf,c);
close(file);
}
}

Hope this helps

Yes. Great! Exactly what I was looking for. I guess I need to include
more headers. But where is it descided in the program that the file opened
written to and eventually closed is going to be a binary or text file?

At the POSIX level, there is no such thing as a "binary" or "text" file. To
the OS (and these calls) it's all just bytes of data.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


.