使用系统(“xxxxx”) [英] using system("xxxxx")

查看:130
本文介绍了使用系统(“xxxxx”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是C编程的新手,遇到了问题。


我的程序已经打开并创建了一个硬盘上的文本文件。

文档名称存储在一个名为output的字符串中。


在程序结束时,我想要使用记事本自动打开outputfile.txt




所以我想我想做的是


系统(notepad.exe%s,输出);


但当然它不起作用。


可以有人告诉我是否可能,如果可能的话。


任何人都可以告诉我一个有完整语法的好网站。我的b $ b有b Primer plus等等,但是他们都没有这些

命令的信息。


非常感谢在预期

解决方案

TO写道:

system(" notepad.exe%s",输出);




system()函数使用给定的

文本字符串调用本机shell。它只需要一个参数,一个指向字符串的指针

将被赋予shell。您可以通过事先创建

字符串来解决您的问题,例如:


char foo [80]; / *这就是我们的命令* /


snprintf(foo,sizeof foo," notepad.exe%s",输出);

系统(foo);


希望有所帮助,

- 约翰


John Valko写道:

TO写道:

> system(notepad.exe%s,输出);



system()函数使用给定的
文本字符串调用本机shell。它只需要一个参数,一个指向字符串的指针,它将被赋予shell。您可以通过事先创建
字符串来解决您的问题,例如:

char foo [80]; / *这就是我们的命令* /

snprintf(foo,sizeof foo,notepad.exe%s,输出);
system(foo);

希望有所帮助,
- 约翰




谢谢约翰,

我会试一试。

Tris


John Valko< jv **** @ gmail.com>写道:

T O写道:

> system(notepad.exe%s,输出);



system()函数使用给定的文本字符串
调用本机shell。它只需要一个参数,一个指向字符串
的指针,它将被赋予shell。您可以通过事先创建字符串来解决您的问题,例如:

char foo [80]; / *这就是我们的命令* /

snprintf(foo,sizeof foo,notepad.exe%s,输出);
system(foo);




请注意,snprintf()函数是C99中的新功能(尽管它可能是某些C90实现中作为扩展提供的
)。


如果你的实现没有提供snprintf(),你可以使用

sprintf()代替(没有sizeof foo参数) - 但是然后呢'' s

由你来确保你不会溢出缓冲区。


-

Keith Thompson(The_Other_Keith ) ks***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


Hi all,

I am very new to C programming and have come across problem.

My programme has opened and created a text document on the hard drive.
The document name is stored in a string called "output".

At the end of the program, I want to open the outputfile.txt
automatically using notepad.

So I figure what I want to do is

system("notepad.exe %s",output);

but of course it doesn''t work.

Can anyone tell me if it is possible and if so how.

Can anyone tell me a good site that has full syntax for such command. I
have C Primer plus etc, and other books but they all lack info on such
commands.

Thanks very much in anticipation

解决方案

T O wrote:

system("notepad.exe %s",output);



The system() function invokes the native shell with the given string of
text. And it takes only one parameter, a pointer to the string which
will be given to the shell. You can solve your problem by creating the
string beforehand, like:

char foo[80]; /* This is what will hold our command */

snprintf(foo, sizeof foo, "notepad.exe %s", output);
system(foo);

Hope that helps,
--John


John Valko wrote:

T O wrote:

> system("notepad.exe %s",output);



The system() function invokes the native shell with the given string of
text. And it takes only one parameter, a pointer to the string which
will be given to the shell. You can solve your problem by creating the
string beforehand, like:

char foo[80]; /* This is what will hold our command */

snprintf(foo, sizeof foo, "notepad.exe %s", output);
system(foo);

Hope that helps,
--John



Thankyou John,
I will give it a go.
Tris


John Valko <jv****@gmail.com> writes:

T O wrote:

> system("notepad.exe %s",output);



The system() function invokes the native shell with the given string
of text. And it takes only one parameter, a pointer to the string
which will be given to the shell. You can solve your problem by
creating the string beforehand, like:

char foo[80]; /* This is what will hold our command */

snprintf(foo, sizeof foo, "notepad.exe %s", output);
system(foo);



Note that the snprintf() function is new in C99 (though it may be
provided as an extension in some C90 implementations).

If your implementation doesn''t provide snprintf(), you can use
sprintf() instead (without the sizeof foo argument) -- but then it''s
up to you to ensure that you don''t overflow the buffer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于使用系统(“xxxxx”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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