我正在使用命令行参数和界面构建这个披萨程序。它应该从参数中返回成分。
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
char *delivery = "";
int thick = 0;
int count = 0;
char ch;
while(ch = getopt(argc, argv, "d:t") != EOF)
switch(ch)
{
case 'd' :
delivery = optarg;
break;
case 't' :
thick = 1;
break;
default:
fprintf(stderr, "Invalid option : %s", optarg);
return 1;
}
argc -= optind;
argv += optind;
if(thick)
puts("thick crust");
if(delivery[0])
printf("To be delivered %s", delivery);
puts("ingredients :");
for(count = 0; count<argc; count++)
{
puts(argv[count]);
}
return 0;
}
在 Windows 中使用命令提示符运行此程序时:
程序 -d 现在 -t
它返回一个错误:
无效选项:现在
我应该如何运行这个程序,为什么会出现这个错误?