我如何运行记事本并让它以c语言打开文本文件 [英] How do i run notepad and let it open a text file in c-language

查看:584
本文介绍了我如何运行记事本并让它以c语言打开文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小软件供个人使用。

我想通过传递文件路径来打开带有记事本的文本文件。

我知道如何在C#中做到这一点。它如下:



使用System.Diagnostics; ///这是启动过程所必需的

I am coding a little software for my personal use.
I want to open a text file with notepad by passing the file path to it.
I know how to do that in C#. it is as the following:

using System.Diagnostics; ///this is necessary to start the process

Process.Start(@"C:\Windows\System32\notepad.exe","C:\myDatabase\namesList.snk");





我想在C-中做同样的事情语言。



我非常感谢你的帮助。



提前感谢



我尝试了什么:



我试图使用shellExecute函数,但没有参数对于要执行的程序打开文件的路径。



就是说;我想将文件路径传递给程序(记事本)并启动它,以便打开指定的文件。



I would like to do the same in C-Language.

I really appreciate your help.

thanks in advance

What I have tried:

I tried to use the shellExecute function, but there was no parameter for the path of the file to be opened by the executed program.

that is to say; I want to pass the file path to the program (notepad) and launch it so that it opens the specified file.

推荐答案

你试试这个



Did you try this

#include <stdlib.h>  

int main () {
    system ("notepad C:\myDatabase\namesList.txt");
    return 0;
}</stdlib.h>







你也可以省略记事本如果文本文件默认程序与记事本关联




You can omit "Notepad" too if the text file default program is associated to notepad


更好的选项将是这个

Better Option would be this
ShellExecute( NULL, "open", 
    "C:\\myDatabase\\namesList.txt",        
    NULL,       
    NULL,       
    SW_SHOWNORMAL 
);


这么多年前我曾经这样做过 - 但它是在DOS系统中。检查是否所有内容仍然相同,我建议你 winapi - 如何在C中运行外部程序? - 堆栈溢出 [ ^ ]



还有一系列spawn和exec命令。我记得,他们就是我用过的东西:帮助 - QNX SDP 6.6文档 [ ^ ]
I used to do this so many years ago - but it was in a DOS system. Checking to see if all is still the same, I refer you to winapi - how can I run an external program In C? - Stack Overflow[^]

There also used to be a family of spawn and exec commands. As I recall, they were what I used: Help - QNX SDP 6.6 Documentation[^]


这篇关于我如何运行记事本并让它以c语言打开文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆