-1
-u ex를 호출 할 때마다이 오류가 발생합니다. ./Randoms -u 100 "이 코드가 무슨 문제입니까? 분할 오류 : 11
다른 모든 경우에는 문제가 없습니다. 왜 그런가? 어떻게 수정해야합니까?
낮은 경계 -I와 상한 사이의 임의의 숫자를 인쇄하려고합니다. -u. 모두 명령 줄 인수로 전송됩니다.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
static char *prgn;
int main(int argc, char *argv[])
{
srand(time(NULL));
int randomnumber;
int nums = 10;
int l = 1;
int u = 100;
int c = 0;
int error = 0;
char *options = ":n:l:u";
prgn = (char *)malloc(sizeof(char)*(strlen(argv[0])+1));
strcpy(prgn,argv[0]);
while ((c = getopt(argc,argv,options)) != -1) {
if (c == '?') {
c = optopt;
printf("illegal option %c\n",c);
} else if (c == ':') {
c = optopt;
printf("missing value for option %c\n",c);
}
else {
switch (c) {
case 'n':
nums = atoi(optarg);
break;
case 'u':
u = atoi(optarg);
break;
case 'l':
l = atoi(optarg);
break;
}
}
}
while (nums !=0){
randomnumber = l + rand() % (u - l);
printf("%d\n", randomnumber);
nums--;
}
c = 0;
return 0;
}
에 의해
당신은 무엇을 발견 했는가 교체? 어디에서 추락 했습니까? 옵션에'u :'가 필요하지 않습니까? – John3136
빌어 먹을 결장이 빠지기까지 4 시간 이상을 소비했습니다. kms. 고맙습니다! –
죄송합니다.이 질문이 이미 해결 된 것을 보지 못했습니다. – clockley1