【发布时间】:2015-09-18 04:54:17
【问题描述】:
我正在做一个程序,它接收一个数字并给你除数的数量。 例如 在 cmd 中:
practica -n 30
预期输出:
1,2,3,5,6,10,15,30
我有这个代码:
void divisor(char *temp1);
int main(int argc,char **argv){
int option;
char *n;
while((option =getopt(argc,argv,"n")) !=-1){
switch(option){
case 'n':
n=optarg;
break;
}
}
divisor(n);
}
void divisor(char *temp1){
char f=*temp1;
int n=f-'0';
int a;
a=1;
while (a<n)
{
if(n%a==0)
printf("%d,",a);
a++;
}
a=n;
if(n%a==0)
printf("%d",a);
printf("\b ");
}
我正在使用命令行,程序关闭。
【问题讨论】:
-
您是否尝试过调试您的应用程序以查看它实际出错的地方?
标签: c string command-line-arguments getopt