We help IT Professionals succeed at work.

Simple File Handling Problem.....

b_harpal asked
hi all,
         I have a file handling proggmm..i just want to know whether it is possible to create the file in some other computer which is on network instead of local c:\..
I have Dos based system connected to other system via TCP/IP..this i have done using Microsoft Client network 3.0..it connects successfully to my other system 'pc2'..now i just want to create a file from my systm to other system 'pc2' ..will it work if i wrote..
fileptr = fopen("d: \\pc2\data\myfile.dat","w"); /* create the file */

Or how should i do it..help me..

Watch Question


will create a file on pc2 IF it has a share called "myshare".

= fopen("d: \\pc2\data\myfile.dat","w");  ???
        "d: \\pc2\\data\\myfile.dat","cw" I think
char file_to_be_open[] = "\\\\pc2\\data\\myfile.dat"

fileptr = fopen(file_to_be_open, "w");

This will open a file on machine "pc2" if "data" is a shared directory on the machine.

char file_to_be_open[] = "d:\\myfile.dat"

fileptr = fope(file_to_be_open, "w");

This will open a file on drive d: where drive d: is a mapped drive (ie drive d: is mapped to "\\pc2\data".

Note the number of slashes in the strings as to put 1 slash in a literal string you need 2 slashes in the typed string (in compilation).

Notes of fopen
"w" opens a file for writing (emptying the file first)
"a" opens a file for appending to the end of the file.

Consider also using CFile() when using files.

dclaydon has the answer.  Note that the two slashes apear only in the source code, not the actual program produced.  That is, if you put a pair of slashes in a string in the source code, the compiler creates a string that has only one slash, for example

const char *S = "A\\B";

creates a string that is 3 characters, not 4, long.


thanx dclaydon...that was good...


thanx nietod...


and thanx everyone..

Explore More ContentExplore courses, solutions, and other research materials related to this topic.