Thread: what is "b:" ??? (input/output)

  1. #1
    Registered User TheSupremeAbode's Avatar
    Join Date
    Jan 2011
    Location
    Portland, OR
    Posts
    10

    what is "b:" ??? (input/output)

    i'm following a textbook to learn C, and the following example was used to show how to Program-Controlled Input and Output files...

    Code:
    #include <stdio.h>
    #define KMS_PER_MILE 1.609
     
    int
    main(void)
     
    {
     
    double miles, kms;
     
    /* set pointers */
    FILE *inp, *outp;
     
    /* open input/output files */
    inp = fopen("b:input_file.txt", "r"); 
    outp = fopen("b:output_file.txt", "w");
     
    /* get and echo info */
    fscanf(inp, "%1f", miles);
    fprintf(outp, "The distance in miles is %.2f.\n", miles);
     
    /* convert distance to kms */
    kms = KMS_PER_MILE * miles;
     
    /* display distance in kms */
    fprintf(outp, "That equals %.2f kilometers.\n", kms);
     
    /* close files */
    fclose(inp);
    fclose(outp);
     
    return(0);
     
    }
    the trouble is, I run it and it doesn't work.

    I have tried searching for "b:" as it was used here:

    Code:
    /* open input/output files */
    inp = fopen("b:input_file.txt", "r"); 
    outp = fopen("b:output_file.txt", "w");
    in google to find out what it does, but I have found nothing.


    What the heck?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    "b:" is a drive letter, used in the DOS/Windows world. Just consider it part of the path. Try substituting it with "c:\\input_file.txt" (note: you have to double the backslash) or, if you're in a *NIX environment, "/home/tsa/input_file.txt".
    If you understand what you're doing, you're not learning anything.

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Or just leave it as "input_file.txt", if the file is in the current working directory.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  4. #4
    Registered User TheSupremeAbode's Avatar
    Join Date
    Jan 2011
    Location
    Portland, OR
    Posts
    10
    Quote Originally Posted by itsme86 View Post
    "b:" is a drive letter, used in the DOS/Windows world. Just consider it part of the path. Try substituting it with "c:\\input_file.txt" (note: you have to double the backslash) or, if you're in a *NIX environment, "/home/tsa/input_file.txt".
    right, okay.

    I was trying to run the above-mentioned program, as a batch file, from a command prompt.

  5. #5
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Wait... what? You put the C code in a file, and gave that file a .bat extension, and tried to execute it?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by TheSupremeAbode View Post
    I have tried searching for "b:" as it was used here:

    Code:
    /* open input/output files */
    inp = fopen("b:input_file.txt", "r"); 
    outp = fopen("b:output_file.txt", "w");
    in google to find out what it does, but I have found nothing.


    What the heck?
    This post makes me feel old. As stated, b: is a drive indicator. But they're using it wrong, because you have to have a separator after it. You can't just b:foo.txt, you need b:\foo.txt. I guess most people now have never had a b drive.

    Quzah.
    ... is old.
    Hope is the first step on the road to disappointment.

  7. #7
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Ah, the ye olde days, when floppies were all we had. The kids have no idea how good they have it these days!
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  8. #8
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    The floopy disks were awesome. A set of 1.2mb and 1.4mb used to store all the games.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  9. #9
    Registered User TheSupremeAbode's Avatar
    Join Date
    Jan 2011
    Location
    Portland, OR
    Posts
    10
    lol

    I didn't save it as .bat, I compiled it from a .c source file; then tried to run the EXE via command prompt

  10. #10
    Registered User TheSupremeAbode's Avatar
    Join Date
    Jan 2011
    Location
    Portland, OR
    Posts
    10
    when computers were louder than vaccum cleaners, this wee lad played Oregon Trail and learnt very fast not to name your family members after the family members who were crossing ye olde trail during game play.

    http://www.elephantjournal.com/wp-co...egon-trail.jpg

    And hunting? Call of Duty doesn't have s*it on Oregon Trail.

    http://www.nostalgiaholic.com/wp/wp-...on-hunting.gif

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Yeah I remember playing lots of Oregon trail. I stupidly tried to ford rivers 2 metres (6 foot) deep. Then I'd go hunting in winter and catch nothing. Good times...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  12. #12
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Quote Originally Posted by quzah View Post
    This post makes me feel old. As stated, b: is a drive indicator. But they're using it wrong, because you have to have a separator after it. You can't just b:foo.txt, you need b:\foo.txt. I guess most people now have never had a b drive.

    Quzah.
    ... is old.
    b:file.txt is valid - it looks for file.txt in the current directory on the B: drive. DOS maintains a current working directory for each drive, and using the letter plus a colon with no slash accesses that current directory so you don't have to retype it in full.

    C:\foo > cd b:\bar REM changes current active dir on B: even though you're in C
    C:\foo > dir b: REM this will display b:\bar since it's the active directory on b:

    Now whether or not that's what's desired in this case is an entirely different matter. Looks dangerous here since you have no idea what you're accessing.

  13. #13
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by KCfromNC View Post
    b:file.txt is valid - it looks for file.txt in the current directory on the B: drive. DOS maintains a current working directory for each drive, and using the letter plus a colon with no slash accesses that current directory so you don't have to retype it in full.

    C:\foo > cd b:\bar REM changes current active dir on B: even though you're in C
    C:\foo > dir b: REM this will display b:\bar since it's the active directory on b:
    As you demonstrated, that's now a cmd convention which is faked by environment vars not an OS convention. On NTFS file systems, b:test.txt would be the test.txt alternate data stream of the extensionless file b. But I think we're all agreed it's a copy error, and not some obsequious path convention.
    Last edited by adeyblue; 01-31-2011 at 02:39 PM. Reason: I didn't abide by normal spelling conventions

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise input/output
    By dhuan in forum C Programming
    Replies: 4
    Last Post: 11-04-2010, 07:50 AM
  2. Replies: 1
    Last Post: 09-24-2009, 01:28 AM
  3. file input/output
    By joker_tony in forum C Programming
    Replies: 3
    Last Post: 08-03-2009, 05:00 PM
  4. Input/Output Streams
    By mikeprogram in forum C++ Programming
    Replies: 6
    Last Post: 12-23-2005, 02:58 PM
  5. Input/Output
    By PaulMelia in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 08:13 AM