gcc compiling (systems call- soft' variable syntax

This is a discussion on gcc compiling (systems call- soft' variable syntax within the C Programming forums, part of the General Programming Boards category; Hi, Could you please help me with the corect syntax for soft' variable with open system call? Code: #ifdef HAVE_CONFIG_H ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    56

    Smile gcc compiling (systems call- soft' variable syntax

    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);
             
            
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    getenv - C++ Reference

    I think that's what you're looking for but your description of your problem wasn't optimal so I'm not sure.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    987
    Syntax like "$path" does not make sense in C. You probably mean to do

    Code:
    #define PATH "/Home_work/My_solution/a.txt"
    fd = open (PATH, O_WRONLY  |O_CREAT,0666);
    Also, you are trying to read from that file descriptor even though you specified O_WRONLY. You probably want to open two file descriptors, one for reading and one for writing.

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    56
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2009, 04:23 AM
  2. Replies: 5
    Last Post: 03-26-2009, 11:02 AM
  3. Variable Call via Another Variable's Content
    By E-Rac in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2005, 12:51 PM
  4. proper function call syntax
    By jerrykelleyjr in forum C++ Programming
    Replies: 9
    Last Post: 12-27-2004, 07:43 PM
  5. Compiling syntax
    By Jez_Master in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2002, 08:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21