Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting a address from the dos prompt and opening it

Status
Not open for further replies.

bob323

MIS
Jan 3, 2001
5
0
0
US
I'm kind of new to C, and I want get a file address from the dos prompt and open it any ideas?
 
This is a pretty basic thing in C. If you take a look at any C book or even a web tutorial, this should be covered.

I assume by "address" you mean a file name. I'm not sure if this will help, but here's a short example that opens and closes a file:

/**** Untested (but if should be fine) ****/

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char **argv)
{
FILE *fp;

if (argc<2) {
fprintf(stderr,&quot;usage: %s <filename>\n&quot;,argv[0]);
return EXIT_FAILURE;
}

fp=fopen(argv[1],&quot;r&quot;);
if (NULL!=fp) {

/* Do stuff with file */

fclose(fp);
} else {
fprintf(stderr,&quot;Failed to open file %s\n&quot;,argv[1]);
return EXIT_FAILURE;
}
return 0;
}

If this isn't what you want, please clarify with another post.



Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top