Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am new to Linux programming, wrote an file writing program,the file is created but the text is file is not in readable format can anyone tell why?
Here is the program
C++
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>

#define BUF_SIZE

int main()
{
int fd;
char* buffer = "hi";
fd = open("/home/abc/Desktop/log.txt", O_WRONLY | O_CREAT | O_APPEND,777);
 ssize_t out = write (fd,;this is me",12);
printf("value of out is %d",out);
close(fd);
}
Posted
Updated 3-Aug-13 3:26am
v2

1 solution

Probably, because your program doesn't compile, and thus doesn't produce an EXE file. So exactly what you are running to create the file, I don't know...

Try changing:
C++
ssize_t out = write (fd,;this is me",12);
To
C++
ssize_t out = write (fd,"this is me",12);

It may not work - I haven't tested it - but at least it will compile and produce an EXE file...
 
Share this answer
 
Comments
Robert Clove 3-Aug-13 11:42am    
ya but the text in the file is not in readable format,
OriginalGriff 3-Aug-13 12:08pm    
So what does it look like? Have you looked at it with a hex editor?
Robert Clove 3-Aug-13 12:31pm    
not with hex editor but the txt file should be normal readable.
OriginalGriff 3-Aug-13 12:39pm    
So the first step is to find out what you do have - that should give clues as to why it isn't readable...
Robert Clove 3-Aug-13 12:41pm    
i have written the above code with this line ssize_t out = write (fd,"this is me",12);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900