使用系统()函数的打开用C在运行时给出的文件名 [英] use of system() function to open a filename given at runtime in C

查看:127
本文介绍了使用系统()函数的打开用C在运行时给出的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用system()函数打开图像,其名称在运行时给出。对于一个固定的名字它的工作原理,但是,错误出如果我通过,因为它不是为两个参数定义的另一个理由。

I want to use the system() function to open an image whose name is given at runtime. For a fixed name it works, but, errors out if I pass another argument as it is not defined for two arguments.

我想要的东西,像下面这样,使用任何功能,可以实现这一点。

I want something like the following, using any function that can achieve this.

system("gthumb <file1>");

,其中文件1存储在运行时给定的文件的名称。

where file1 stores the name of the file given at runtime.

谢谢!

推荐答案

您应该避免使用系统()电话。

不管怎样,你要在这里做什么,首先是计算完整的命令行,使用的sprintf()。你必须做一些事情,如:的sprintf(字符串,gThumb的%S,文件1); 然后,你叫系统(串);

Anyway, what you have to do here, first is to compute the complete command line, using sprintf(). You have to do something like: sprintf(string, "gthumb %s", file1); and then, you call system(string);

这篇关于使用系统()函数的打开用C在运行时给出的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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