I've used the following code to invoke MSWord from a DOS based C compiler unsuccessfully....Where am I going wrong?
#include <stdio.h>
#include <stdlib.h>
main()
{
system("C:\helpme!.doc");
}
Thanks in advance.
Printable View
I've used the following code to invoke MSWord from a DOS based C compiler unsuccessfully....Where am I going wrong?
#include <stdio.h>
#include <stdlib.h>
main()
{
system("C:\helpme!.doc");
}
Thanks in advance.
It should be
Code:system("C:\\myme!.doc");
first main() should return a value.
second you'll need an extra slash for the file name.
Code:#include <stdlib.h>
int main()
{
system("C:\\helpme!.doc");
return 0;
}
I revised the program (i.e. put the extra slash in and put in int main() and return 0) and I still get a "Bad command or file name" when I try to execute the program. Any other suggestions? Appreciate the help.
Not to sound condescending: Are you sure the file's there?
Yep, the files there. I thought of that...I tried on various files to try to get this working. I also tried different things on the system function such as a "copy" and "dir" and those things work correctly as far as I saw.
OK - try smth like this:
system("c:\\winword mydoc.doc");
I don't know if Word will take parameters like that, but it works with notepad...
I tried:
system("c:\\winword mydoc.doc");
and
just for laffs,
system("c:\\winword.exe mydoc.doc");
But, unfortunately, it's a no go on both lines....
If you go to your command prompt and type >>C:\helpme!.doc<<
does that open the document?
Include windows.h and use one of the ShellExecute family of functions. There is info on this at msdn.
That's just it. When I go to the command prompt and type in my document name (i.e. >>c:\mydoc.doc<<) , MSWord does start up. But I can't get it to start up within my program. That's why I figured that I may have been missing something (possibly in my use of the system function).
I'm shootin' in the dark, but try one of the spawn functions (they work better, anyways)
what is the name of the file you are trying to open?
Well you could use the full path to microsoft word.
A document file is not the same as an executable file. Govtcheez had the right idea, but try this instead:
Code:#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int main()
{
system("c:\\helpme!.doc >> C:\\WINWORD");
return 0;
}