此作业要求参见[https://edu.cnblogs.com/campus/nenu/2019fall/homework/6582]
作业要求:1.熟悉命令行和控制台
请用C语言开发应用程序d.exe,从控制台指令读入命令行参数,并在控制台分别打印出a、b、c的值。运行效果形如下面的示例
提醒 : 请注意在以下代码示例中,d.exe
与a=1 b=2 c=3
在同一行中,没有换行。
">"称为提示符,是操作系统的一部分,不是你的程序的输出。
>d.exe a=1 b=2 c=3
1
2
3
>d.exe a=11 b=22 c=33
11
22
33
答:
代码如下所示:
#include <stdio.h> int main(int argc,char *argv[]){ int a,b,c; sscanf(argv[1],"a=%c",&a); sscanf(argv[2],"b=%c",&b); sscanf(argv[3],"c=%c",&c); printf(" "); printf("%d ",a); printf("%d ",b); printf("%d",c); printf(" "); return 0; }
运行效果图: