I want to write a program that can run a file in my hard disk.For example,a test.bmp file is there in location D:\home\test.bmp,that program should open(like double clicking on it ) that file (test.bmp) and i can view the image contained in the file.

I want to write a program that can run a file in my hard disk.For example,a test.bmp file is there in location D:\home\test.bmp,that program should open(like double clicking on it ) that file (test.bmp) and i can view the image contained in the file.

For bitmap images (or images in particular) its a bit lengthy process(which I sadly don't know myself).I will just tell you the process to open any file for example a text file in particular.

Steps:
1>Make your code take the path of the file needed to be opened either through command line as argv or through scanf in the form of a string.
2>Combine this path taken from the user with other parts of a command like edit (edit <path of file >) to form the final string.
3>Pass this string as system call by the usage of function system
as

system("<final string>");

Never use system()
Just use OS api, win32 api if Windows (SH)

I couldn't understand step-2...ie,making finale string.Suppose I have to open the file located @ d:\hello.txt,My command line system("d:\hello.txt ") doesn't work at all.What should i have to do for that task.

I use Turbo c ,How can I make that program,I use Windows Xp.

I use Turbo c ,How can I make that program,I use Windows Xp.

I use Turbo c ,How can I make that program,I use Windows Xp.

Turbo C is not an adequate compiler for Windows XP.
This is a helpful link to modern compilers.

I couldn't understand step-2...ie,making finale string.Suppose I have to open the file located @ d:\hello.txt,My command line system("d:\hello.txt ") doesn't work at all.What should i have to do for that task.

Well what Aia told is right C is not a good compiler and the method suggested by me is not too good but it will work in a way.

Well what i meant was that system() is the call given to run any command which you would have run in command prompt so in command prompt if u needed to open a file at d:\hello.txt you would give

>edit d:\hello.txt [ENTER]

now this is the string you need to send to system to execute that dos command through C file as:

system("edit d:\hello.txt");

I hope you got it now.

my program is:
#include<stdlib.h>
#include<stdio.h>
int main()
{

system("edit D:\hello.txt");
return 0;
}
It doesn't gives any error,But couldn't open the file D:\hello.txt

That thing should work.It surely works for me.May be its due to your compiler.Some compilers like TC brands don't support usage of system calls so easily.I use devc++ compiler and it works fine with that and also gcc compilers too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.