windows下的这个参数怎么输入

清欢万岁! 2020-01-09 08:37:49
这个主函数里的两个参数怎么搞
/* count.c -- using standard I/O */
#include <stdio.h>
#include <stdlib.h> // exit() prototype

int main(int argc, char *argv[])
{
int ch; // place to store each character as read
FILE *fp; // "file pointer"
unsigned long count = 0;
if (argc != 2)
{
printf("Usage: %s filename\n", argv[0]);
exit(EXIT_FAILURE);
}
if ((fp = fopen(argv[1], "r")) == NULL)
{
printf("Can't open %s\n", argv[1]);
exit(EXIT_FAILURE);
}
while ((ch = getc(fp)) != EOF)
{
putc(ch,stdout); // same as putchar(ch);
count++;
}
fclose(fp);
printf("File %s has %lu characters\n", argv[1], count);

return 0;
}
...全文
57 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
寻开心 2020-01-09
  • 打赏
  • 举报
回复
把数据文件(比如 data.txt)和你编译出来的执行文件(比如:test.exe文件)放到同一个目录下
方法1:
为你的exe文件创建一个快捷方式,编辑快捷方式, 在参数输入 data.txt
然后双击你的快捷方式,运行
方法2
运行cmd命令, 进入到这个文件夹后,人工输入。test data.txt
方法3
在你的编辑器里面,更改工程设置, 找到执行命令的部分,把参数设置为“ data.txt”
gouyanfen 2020-01-09
  • 打赏
  • 举报
回复
运行时跟在后面就是参数 比如 a.exe "bbb.txt"

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧