?
=?iso-8859-1?q?Fredrik_H=E5kansson?=
Hello!
Please explain I'm trying to learn. I try to write the string /tmp/duken
into a file named /tmp/duken just for learning. I know there are other
functions like fopen() and so on but why is the below not working??
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
main()
{
int fd, wr, end, n;
const char *file = "/tmp/duken";
n = strlen(file);
printf("The lenght is %d \n",n);
if ((fd = open(file, O_CREAT, S_IRWXU)) < 0)
printf("Can't open %s", file);
if ((wr = write(fd, file, n)) <= 0)
printf("Unable to write to %s %d was the error\n",file,wr);
fsync(fd);
end = close(fd);
return end;
}
Please explain I'm trying to learn. I try to write the string /tmp/duken
into a file named /tmp/duken just for learning. I know there are other
functions like fopen() and so on but why is the below not working??
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
main()
{
int fd, wr, end, n;
const char *file = "/tmp/duken";
n = strlen(file);
printf("The lenght is %d \n",n);
if ((fd = open(file, O_CREAT, S_IRWXU)) < 0)
printf("Can't open %s", file);
if ((wr = write(fd, file, n)) <= 0)
printf("Unable to write to %s %d was the error\n",file,wr);
fsync(fd);
end = close(fd);
return end;
}