Call by Value 에서 Reference로 변경하는법...
MinA
질문 제목 : 구조체배열 call by reference변경하는법
지금 제가 call by value로 했는데 call by reference로 변경해야하는데 오류가 발생하네요;
아직 초보라 문법을 제대로 변경 못한것 같은데 어느부분이 잘못됬는지 좀 알려주세요..
질문 내용 :
정상작동하는 코드
-----------------
// 3번문제
#includestdio.h
#includestdlib.h
#includetime.h
#includemath.h
struct point
{
int x;
int y;
char dummy[100];
}a[10000000],b;
void pointrandom(struct point *a);
void distance(struct point [], struct point);
void main()
{
clock_t start,finish;
srand((unsigned)time(null));
printf(잠시만 기다려주세요...\n);
pointrandom(a);
printf(좌표를 입력하세요(단, 0 = x = 10000 , 0 = y = 10000):\n);
scanf(%d %d,&b.x,&b.y);
start = clock();
distance(a,b);
finish = clock();
printf(검색시간 : %f초\n,(double)(finish-start)/clk_tck);
}
void pointrandom(struct point *a)
{
int i;
for(i=0;i10000000;i++)
{
a[i].x=rand()%10001;
a[i].y=rand()%10001;
}
}
void distance(struct point a[], struct point b)
{
int i;
double distance;
for(i=0;i10000000;i++)
{
distance=sqrt((a[i].x-b.x)*(a[i].x-b.x)+(a[i].y-b.y)*(a[i].y-b.y));
if(distance100)
printf(좌표=(%5d, %5d) / 거리=%g\n,a[i].x, a[i].y,distance);
}
}
수정중인 코드
-----------
// 3번문제
#includestdio.h
#includestdlib.h
#includetime.h
#includemath.h
struct point
{
int x;
int y;
char dummy[100];
}a[10000000],b;
void pointrandom(struct point *a);
void distance(struct point *[], struct point *);
void main()
{
clock_t start,finish;
srand((unsigned)time(null));
printf(잠시만 기다려주세요...\n);
pointrandom(a);
printf(좌표를 입력하세요(단, 0 = x = 10000 , 0 = y = 10000):\n);
scanf(%d %d,&b.x,&b.y);
start = clock();
distance(a,b);
finish = clock();
printf(검색시간 : %f초\n,(double)(finish-start)/clk_tck);
}
void pointrandom(struct point *a)
{
int i;
for(i=0;i10000000;i++)
{
a[i].x=rand()%10001;
a[i].y=rand()%10001;
}
}
void distance(struct point *a[], struct point *b)
{
int i;
double distance;
for(i=0;i10000000;i++)
{
distance=sqrt((a[i]-x-b-x)*(a[i]-x-b-x)+(a[i]-y-b-y)*(a[i]-y-b-y));
if(distance100)
printf(좌표=(%5d, %5d) / 거리=%g\n,a[i]-x, a[i]-y,distance);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |