using system() calls

Discussion in 'C' started by doubleOO, Oct 20, 2015.

  1. doubleOO

    doubleOO New Member

    Joined:
    Oct 20, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am running this code in Windows 7 it compiles and runs fine, but it does not create the reports.log file. I have run the code in Ubuntu and it works fine. Can anyone help figure out what I need to change to make it create the file. Thank you for your help.
    Code:
    /*includes*/
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    //prototypes
    char* now();
    
    int main()
    {
        //local variables 
        char comment[80];
        char cmd[120];
    
        fgets(comment, 80, stdin);
        sprintf(cmd, "echo %s %s >> reports.log", comment, now());
    
        system(cmd);
    
        return 0;
    }
    
    /************************************************************************
    * FUNCTION:        FunctionName()
    * DESCRIPTION:     Displays the parking lot status at the beginning of
    *					the day
    * INPUT:
    *    Parameters:   aStack - this is the car stack
    *                  vanStack - this is the van stack
    *
    *    File:         N/A
    *
    * OUTPUT:
    *    Return Value: N/A
    *
    *    Parameters:   N/A
    *
    *    File:         N/A
    *
    *
    * CALLS TO:        N/A
    ************************************************************************/
    char* now()
    {
        time_t t;
        time (&t);
    
        return asctime(localtime (&t));
    }
    
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Are you sure the file wasn't created at all? It's likely to have been created where you don't expect it. Try "dir/s c:\reports.log" and repeat for all drives on your system - that'll find it if it's there.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice