writing to file is not readable by user

In the following code segment I write to some file using

, but this write is not readable by me when i open the file. any helps would be thankful.

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<errno.h>
#include<fcntl.h>
#include<ctime>
#include<cmath>
#include<iostream>
using namespace std;
#define FILE_MODE  (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
#define _PARAM 5
#define _RAND_RANGE 100
#define DOWNLOADER_FIFO "/tmp/fifo.0"

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

     int fd, value = 19;
   int n;
   char c[10];

   if( (fd = open("file.txt", O_WRONLY | O_CREAT, FILE_MODE) ) < 0 ){
        perror("file creation failed..\n");
          return false;
   }      sprintf(c, "%d", value);
          if((n = write(fd, c, sizeof c)) < 0){
                  perror("\n");
                     return false;}
   close(fd);

  return 0;
}

Looks good, but maybe the file was already there chmod 200 ? Man Page for open (All Section 2) - The UNIX and Linux Forums

What are the permission for the created file.txt ? Can you check the file mode creation mask of your shell (simply type umask in the shell).

cheers, Lo�c

The shell umask is a call to umask() to set the process mask, which is inherited, like signals, environment and fd (but they may be close-on-exec), and is not stored within the shell programs's allocated variables.

The open man page says:
The argument mode specifies the permissions to use in case a new file is created. It is modified by the process's umask in the usual way: the permissions of the created file are (mode & ~umask). Note that this mode only applies to future accesses of the newly created file; the open() call that creates a read-only file may well return a read/write file descriptor.

Yeah, right. Thanks.

But if the file.txt has not the right permission, I'd expect a "file creation failed..." error message?

Cheers, Lo�c

after transfered a txt file from pc to unix using FTP, how can i open it in unix?
anybody can help?

Check out the modes you have specified.