Hi,
Could you please help me with the corect syntax for soft' variable with open system call?
Code:#ifdef HAVE_CONFIG_H #include <config.h> #endif #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> //used for exit() #include <string.h> #include <fcntl.h> #include <unistd.h> #include <assert.h> #include <error.h> //prototypes /*******************************************************************************/ int main() { int fd,length=0; int size; char read_buffer[80]; char write_buffer[]="dddddddddddddddddddddddddddddddddd"; path=//Home_work//My_solution//a.txt; //open the file, if it doesn't exist create it with the following permission access fd = open ("$path",/* O_RDONLY */ O_WRONLY |O_CREAT,0666); if (fd == -1) { /* The open failed. Print an error message and exit. */ printf("error opening file: \n"); exit(-1); } /* Read the size of the data in the file. */ length = read (fd, read_buffer, sizeof (read_buffer)); size=sizeof(read_buffer); printf("sizeof(read_buffer)=%d\n",size); printf("length=%d\n",length); printf("fd =%d\n read_buffer= %s\n ",fd ,read_buffer); length = write (fd, write_buffer, strlen (write_buffer)); printf("length=%d\n",length); printf("write_buffer =%s\n",write_buffer); printf("fd =%d\n",fd); // Close the file descriptor, close (fd); }



LinkBack URL
About LinkBacks


