Find the answer to your Linux question:
Results 1 to 2 of 2
I am writing a programme in C. It resides in the ~/Projects/ProjectName/src directory. There is a subdirectory in ProjectName called Formulas. One of the source files of my programme queries ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2004
    Posts
    94

    Question about C


    I am writing a programme in C. It resides in the ~/Projects/ProjectName/src directory. There is a subdirectory in ProjectName called Formulas. One of the source files of my programme queries certain files in the Formulas directory by making a system call:

    system("cat ../Formulas/FormulaFile");

    But this only works when I call the executable from the src subdirectory. I does not work when the executable is called from any other directory.

    What is the best method for solving the problem, other than to provide the full path name? I would like a solution that would make the programme transferrable to other computers as well.

    Thanks in advance for your help.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,809
    There are a number of solutions. The reason it's failing is because the 'cat' command has been given a relative pathname to the file to read. Try using the absolute path, and it'll work great. Even better, you can have the path specified by environment variable or even in a config file somewhere to get it right across different machines.
    Linux user #126863 - see http://linuxcounter.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •