#include <stdio.h>
int get_line_parameter(int x1, int y1, int x2, int y2, float *slope, float *yintercept)
{
if(x1-x2 == 0)
return -1;
*slope = (float)(y1-y2)/(float)(x1-x2);
*yintercept = y1 - (*slope)*x1;
return 0;
}
int main(void) {
float *s, *y;
int x1,x2,y1,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
if(get_line_parameter(x1,y1,x2,y2, s, y) == -1)
printf("에러");
else
printf("%.2f %.2f",s,y);
return 0;
출력값이 안나오고 그냥 종료되여 입력만 받구..
- dc official App
s랑 y앞에 * 붙여야되지않나 저건 그냥 주소값출력하는거잖여
그렇게하면 컴파일 에러 뜨더라구여 float s, y로 포인터 선언 말구 그냥 선언하고 *s, *y로 함수 호출하면 되긴 하던데
printf 쪽에 틀림
엥 어뜨케여?
float s y로 선언하고 함수호출할때 &s &y로 불러야지
printf 는 value를 쏴줘야되는데 float ptr를 쏴주고있잖아
음 그럼 printf에서 &s,&y로 해야하는건가여 근데 이래도 안나오는데 머지 아
222.103 말이 맞음 맨위에 float s,y 로 일반 float 변수로 하고 if(get_line_parameter(x1,y1,x2,y2, s, y) == -1) 에서 &s, &y 로 넘기면 됨
지금 코드 대로하면 정작 float내용 받을곳은 없이 포인터 변수밖에 없어서 float 받을 방법이 없음 s랑 y에 쓰레기 주소값들어가 있어서 참조하는 순간 프로그램 쫑남. 뭐 float *s=new float; float *s=malloc 같은걸로 하면 얘기가 틀린데 그렇게 동적할당 필요 애초에 없음