This is my code
Code:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
char *StrOne = "This is String One\n";
char *StrTwo = "This is string Two\n";
int main(int argc, char *argv[])
{
int fd;
if (argc != 2)
printf("_______@_@______\n\n");
else
{
if ((fd = open(argv[1], O_CREAT|O_EXCL, S_IRUSR|S_IWUSR)) == -1)
{
perror("Open");
exit (2);
}
if (write(fd, StrOne, strlen(StrOne)) != strlen(StrOne))
{
perror("Write\n");
exit (1);
}
lseek(fd, SEEK_SET, 1000);
if (write(fd, StrTwo, strlen(StrTwo)) != strlen(StrTwo))
{
perror("Write\n");
exit (1);
}
close (fd);
}
return 0;
}
this is result:
Code:
coat@linux:~/codetest/lseek_null$ ./a.out Nds
Write: Bad file descriptor
Thx you every body
三克油矮里八地。。。。