Home Directory

This is a discussion on Home Directory within the C Programming forums, part of the General Programming Boards category; fopen("~/routz.txt", "r"); ain't working, how can I tell the program that the file is in the home users' directory?...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2

    Home Directory

    fopen("~/routz.txt", "r"); ain't working, how can I tell the program that the file is in the home users' directory?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Without error checks.
    Code:
    char path[1000];
    sprintf( path, "%s/%s", getenv("HOME"), "routz.txt" );
    fopen( path, "r" );

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Or, if "~" works in chdir():
    Code:
    chdir("~");
    fopen("./routz.txt", "rt");
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  2. Not able to access directory of home folder
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 02-06-2008, 01:45 AM
  3. how to get current user home directory
    By George2 in forum Linux Programming
    Replies: 4
    Last Post: 05-08-2007, 02:46 PM
  4. Accessing the 'home' directory path?
    By smoothdogg00 in forum C Programming
    Replies: 3
    Last Post: 04-30-2006, 10:51 AM

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