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

1. ## 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. "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".

3. Or just leave it as "input_file.txt", if the file is in the current working directory.

4. Originally Posted by itsme86
"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. Wait... what? You put the C code in a file, and gave that file a .bat extension, and tried to execute it?

6. Originally Posted by TheSupremeAbode
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.

7. Ah, the ye olde days, when floppies were all we had. The kids have no idea how good they have it these days!

8. The floopy disks were awesome. A set of 1.2mb and 1.4mb used to store all the games.

9. 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. 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. 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...

12. Originally Posted by quzah
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. Originally Posted by KCfromNC
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.